This is an archive of the Maximo Yahoo Community. The content of this pages may be a sometimes obsolete so please check post dates.
Thanks to the community owner Christopher Wanko for providing the content.
I'm working on an Automation Script to validate a custom attribute in the PERSON table. 99% of the time, this attribute should not be NULL; but I need to accommodate those rare instances when it should be NULL. Then if there is a value, there's a handful of tests it should run to make sure the value given is at least seemingly valid. For example, the value in the field will always be 6- or 7-characters long (unless it is NULL); and if it is 7-characters it will always start with a '900'.
Anyways, I've got the script working correctly for all the validity tests, but not for NULL. What I want to happen is that if it is NULL, it prompts the user with some info to essentially say, "Hey, you left that field blank. Usually it should be filled in. It should be filled in if this, this, this or this. Do you need to fill in the blank?"
If YES, then the UI should make the attribute required.
If NO, then let it stay NULL -- continue on with the Save operation.
This script is Object Launchpoint-based (couldn't use an Attribute Launchpoint because it wouldn't fire if it was left NULL). It is configured to run on Save, Add or Update, Before Save.
I've got two issues here:
1) Clicking YES doesn't do anything. It just goes ahead and allows the Save. I want it to prevent the Save and make that attribute required -- so the user has to supply a value before Saving.
2) On the Person app, I have Conditional UI showing or hiding a field based on the values in other fields. None of the fields involved in the Conditional UI "thing" are this field I'm trying to validate with the script. But when the script fires, it keeps toggling back and forth between showing and hiding that field. Like if I put in a 5-character value for the field I'm trying to validate, it throws the error according to the script, but it un-hides the other field. Then I correct my mistake, or change the value to some other condition that fails the tests (like having an '8' as the first character of a 7-digit value), it will re-hide it.
My script is almost an exact copy-and-paste from an example I found in official IBM documentation. Here's the script as it is now. Any help would be appreciated.
if not pccidnum:
# Business logic implementation if user selects Yes choice (clicks Yes button)
def yes ():
pccidnum_required = True
# Business logic implementation if user selects No choice (clicks No button)
def no ():
pccidnum_required = False
# Business logic to present the choice message initially
def dflt ():
params=[str(pccidnum)]
# Use the service utility's yncerror() method to push the choice message
service.yncerror("person", "PccidnumIsNull", params)
# Declare the user input choices and the corresponding functions implemented in this script
cases = {service.YNC_NULL : dflt, service.YNC_YES : yes, service.YNC_NO : no}
# Make sure the choice message is presented only
# if the field validation was triggered from user interface
if interactive:
# Use the service utility's yncuserinput() method to trigger the entire interaction
# User's response is stored in a local variable x
x = service.yncuserinput()
# Process the user input using Jython's case statement
cases[x]()
else:
if pccidnum.isdigit() == False:
errorgroup='person'
errorkey='PccidnumNaN'
elif len(pccidnum) < 6:
errorgroup='person'
errorkey='PccidnumTooShort'
elif len(pccidnum) > 7:
errorgroup='person'
errorkey='PccidnumTooLong'
elif len(pccidnum) == 6 and not (pccidnum.startswith('0') or pccidnum.startswith('1') or pccidnum.startswith('2')):
errorgroup='person'
errorkey='PccidnumInvalid6'
elif len(pccidnum) == 7 and not pccidnum[0:3]=='900':
errorgroup='person'
errorkey='PccidnumInvalid7'
else:
pccidnum_required = True
Travis Herron
In my experience, it's better to first trap the NULL / NOT NULL condition, then convert the NULLs to some sentinel value that allows for switching on the result. It goes back to handling a ternary value with a binary tool.
So, if you can first convert your NULLs to some special value first, your case logic should be much simpler and consequently ruling out the NULL handling from your issues.
---In MAXIMO@yahoogroups.com, <therron@pcci.edu> wrote :
I'm working on an Automation Script to validate a custom attribute in the PERSON table. 99% of the time, this attribute should not be NULL; but I need to accommodate those rare instances when it should be NULL. Then if there is a value, there's a handful of tests it should run to make sure the value given is at least seemingly valid. For example, the value in the field will always be 6- or 7-characters long (unless it is NULL); and if it is 7-characters it will always start with a '900'.
Anyways, I've got the script working correctly for all the validity tests, but not for NULL. What I want to happen is that if it is NULL, it prompts the user with some info to essentially say, "Hey, you left that field blank. Usually it should be filled in. It should be filled in if this, this, this or this. Do you need to fill in the blank?"
Sounds like good advice. . .if I could get it to work!
I'm trying to do more research on the subject, and I guess the whole yes/no choice thing is new in 7.6. And in developerWorks there's a discussion that started before 7.6 was released where they were wondering if/how you could manipulate the UI based on the yes/no choice.
So now 7.6 is out there, and IBM made a sample script where it shows you how to "get the user's input from a Yes/No choice message" but all the sample script really does is write to the Log. It doesn't "do" anything. I'm now stuck wondering if it actually can "do" what I need it to do.
And yes, I did try your suggestion. I rewrote the script so that if the user picks 'Yes' then the NULL field has its value set to 'XXXXXX', which is an invalid value so it should throw another error later on. I couldn't get it to work. So either my script is wrong or the Yes/No choice abilities just aren't actually functional.
Actually, just before I hit 'Send' here I decided to read another article, where it is saying the scripts are unable to "get hold of the UI Session" -- that sounds a lot like my problem. . .
>> Actually, just before I hit 'Send' here I decided to read another article, where it is saying the scripts are
>> unable to "get hold of the UI Session" -- that sounds a lot like my problem. . .
The more I thought about this, the more I realized that you actually want an interactive dialog to emerge, and that feels like Java to me.
I don't think you are going to get the check-on-NULL without a dialog.
-C
I think I got it to work. Take a look at this:
http://pastebin.com/V9HMDqwE http://pastebin.com/V9HMDqwE
This is an MSE script that I used to create the message and the script with the launch point.
I did not reproduce your scenario in its entirety, just the core piece. I used the description of the asset as the field with the value. With the message/script deployed, if you attempt to save an asset with no description you get the dialog with the Yes/No. If you click Yes, the record saves as is. If you click No, the script makes the field required and this results in another immediate message popup indicating that the field does not have a value (this is redundant, but I don't know how to remove it; from what I understand this should not be a big issue as this scenario occurs only in less than 1%?). Once the user enters the value, the record can be successfully saved.
This was done in Maximo 7.6. The script fires on Validate event.
Yurie Nagorny
Definitely not an entry-level assignment! Let's see if it deploys.
-C
Hooray!!!
Changing the Launchpoint Type to "Validate Application" (from "Save" -- Add/Update) and setting the FieldFlag with Java code instead of Jython code seems to do the job!
Travis Herron
What was the final working code?
My requirements were:
1) The IDNUM field should "almost always" have a value, but there are occasional times (less than 2%) where it would be right to be NULL
2) When it does have a value, it should only have 6 or 7 characters
3) All characters should be numbers (but sometimes there's a leading zero, so it is not stored in the database with a numeric datatype)
4) If it has 6 characters, the first character can only be 0,1,or 2
5) If it has 7 characters, the first three digits will be 900.
The only variable in the script is idnum which is bound to PERSON.IDNUM (a custom field we created).
Script runs against the PERSON object. It has an Object Launchpoint and runs on the "Validate Application" event.
Here it is:
from psdi.mbo import MboConstants
if not idnum:
# Business logic implementation if user selects Yes choice (clicks Yes button)
def yes ():
mbo.setFieldFlag('IDNUM', MboConstants.REQUIRED, True)
# Business logic implementation if user selects No choice (clicks No button)
def no ():
mbo.setFieldFlag('IDNUM', MboConstants.REQUIRED, False)
# Business logic to present the choice message initially
def dflt ():
params=[str(idnum)]
# Use the service utility's yncerror() method to push the choice message
service.yncerror('person', 'IdnumIsNull', params)
# Declare the user input choices and the corresponding functions implemented in this script
cases = {service.YNC_NULL : dflt, service.YNC_YES : yes, service.YNC_NO : no}
# Make sure the choice message is presented only
# if the field validation was triggered from user interface
if interactive:
# Use the service utility's yncuserinput() method to trigger the entire interaction
# User's response is stored in a local variable x
if mbo.isNull('IDNUM'):
x = service.yncuserinput()
# Process the user input using Jython's case statement
cases[x]()
else:
if idnum.isdigit() == False:
errorgroup='person'
errorkey='IdnumNaN'
elif len(idnum) < 6:
errorgroup='person'
errorkey='IdnumTooShort'
elif len(idnum) > 7:
errorgroup='person'
errorkey='IdnumTooLong'
elif len(idnum) == 6 and not (idnum.startswith('0') or idnum.startswith('1') or idnum.startswith('2')):
errorgroup='person'
errorkey='IdnumInvalid6'
elif len(idnum) == 7 and not idnum[0:3]=='900':
errorgroup='person'
errorkey='IdnumInvalid7'
else:
mbo.setFieldFlag('IDNUM', MboConstants.REQUIRED, True)
That's wicked cool, Trav, nice write up.
I totally agree - thanks Travis!
Shannon
From: MAXIMO@yahoogroups.com [mailto:MAXIMO@yahoogroups.com]
Sent: Wednesday, March 1, 2017 9:27 AM
To: MAXIMO@yahoogroups.com
Subject: [MAXIMO List] Re: need help with Automation Script Yes/No Choice
That's wicked cool, Trav, nice write up.