- 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 12:41 PM
How are you setting company field value on the form? are you setting using any on load script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 01:10 PM
Hi srnwebie,
This is on incident form and the company field is a reference field from core_company table. Either SD add company via lookup or if caller is added first company is auto populated.
| ||||||||
<rendered_body>
|
Thanks for helping
Ellie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 01:11 PM
if(g_form.getValue('gr.name').indexOf("ABB") != -1 ){
g_form.setSectionDisplay('company', true);
}
else {
g_form.setSectionDisplay('company', false);
This appears incorrect to me ...
Using single quotes around the gr.name will force it to NOT be evaluated... and double quotes inside javascript is always dicey ...
I'd suggest trying:
if(g_form.getValue(gr.name).indexOf('ABB) != -1 ){
g_form.setSectionDisplay('company', true);
}
else {
g_form.setSectionDisplay('company', false);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 01:30 PM
Hi Tony,
I have made the recommended changes but the behaviour is still the same the section tab briefly appears for all companies and then disappears again.
Any other idea on this?
Many Thanks,
Ellie