- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 12:20 PM
Hi All,
I have 2 client scripts both are same as below 1 onload and the other on change.
The problem I have with the below script is that the section tabs are only briefly shown regardless if condition is met or not. I added the alert(gr. name); to check that the company name returned matches my if condition but despite a match the tabs are only shown briefly and then hidden again.
Default for the section is show.
I think the problem lies in the if condition but I am unable to figure out what it could be.
Does anyone have any idea what is going on with my script and why its behaving this way?
var gr = new GlideRecord('core_company');
gr.addQuery('sys_id', g_form.getValue('company'));
gr.query(myCallbackFunction); //Execute the query with callback function
function myCallbackFunction(gr){
while(gr.next()){
alert(gr.name);
if(g_form.getValue('gr.name').indexOf("ABB") != -1 ){
g_form.setSectionDisplay('company', true);
}
else {
g_form.setSectionDisplay('company', false);
Many Thanks,
Ellie
PS: I have the 2 types of script at the moment as there are a lot of incidents with ABB company that don't display the tab but there will not be an onchange happening on these. Any better idea on this also welcome
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 01:52 PM
Hi Ellie,
I'm not very good with the callback function kind of script. Could you explain what the requirement is and may be i can provide an alternate script? The sections should appear on the form if the company's name contains the phrase 'ABB'?
If so, may be try this script: (In the script part of a UI policy - this way you only need the script in one place and prevents writing the same script twice, onLoad and onChange)
UI Policy When to run:
Dot-walk to the Name of the Company. (If you select show related fields, it shows the related fields of all reference field) and choose 'Contains' and give your phrase.
...here's the script part:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 02:33 PM
I think what tobrien is trying to say is:
g_form.getValue('fieldname') gives you the value in the field that is passed to it. It has to be the field name on the form but the statement in your script: (g_form.getValue(gr.name)) implies that gr.name is the name of the company field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 02:43 PM
Ms Ellie ...
var gRec = new GlideRecord('core_company');
The GlideRecord mechanism gives you the ability to 'filter' records based upon the number of
gRec.addQuery('someTableField1', aValue1);
gRec.addQuery('someTableField2', aValue2);
gRec.query(); // this does the work
gRec.next(); // puts you at the first and then subsequent (for each gRec.next() ) rows. ALL COLUMNS are returned
Soooooooo if the column name is a string in your [core_company] table, then
something like gr.name.indexOf('ABB') > 0 should be TRUE when the name has ABB anywhere in it.
You could try this ==>
var lStr = gr.name;
alert(lStr.indexOf('ABB'));
to see ensure you are getting an integer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 01:52 PM
Hi Ellie,
I'm not very good with the callback function kind of script. Could you explain what the requirement is and may be i can provide an alternate script? The sections should appear on the form if the company's name contains the phrase 'ABB'?
If so, may be try this script: (In the script part of a UI policy - this way you only need the script in one place and prevents writing the same script twice, onLoad and onChange)
UI Policy When to run:
Dot-walk to the Name of the Company. (If you select show related fields, it shows the related fields of all reference field) and choose 'Contains' and give your phrase.
...here's the script part:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 01:56 PM
Hi Veena,
I will try this now and let you know.
Thanks,
Ellie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 02:05 PM
Hi Veena,
That works correctly (why didn't I think of that )
Thanks a million!
Ellie