- 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 01:38 PM
Hi Ms. Ellie ...
If it were me the first thing I'd do is comment out everything and have just this ==>
g_form.setSectionDisplay('company', true);
If you still see the COMPANY section come then go -- then I'd be looking at any UI POLICIES that are making it 'VISIBLE = FALSE'
The UI POLICIES act last after (for example) any OnLoad scripts you might have... the usual way you can see this is what you've described where something appears briefly then goes away -- its almost always a UI POLICY getting you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 01:54 PM
Hi Mr Tony
Its not a UI policy I know for sure that there isn't one.
What I have tried earlier was:
added
var comp = 'ABB';
Then changed if statement to the below
if((comp).indexOf('ABB') != -1){
and this worked section stayed displayed
.
Is my GR query correct? Alert shows company name but I don't know how to express this but it feels like once company name is passed to the if statement something is lost.
Thanks,
Ellie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 02:05 PM
Hi Ms. Ellie (its a southern thing ;<>)
I see you've redone the environment to use the UI POLICY -- that is a good thing.
But after (re)analysing your original script I am a bit confused.
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);
//This gets you the NAME of the company :: gr.name
//This next line seems to imply that you have a form variable called {whatever the value of gr.name is} For example, suppose gr.name = 'Tonys Company Name'
if (g_form.getValue(gr.name).indexOf('ABB') != -1 ) { // this line will fail UNLESS you have a variable named 'Tonys Company Name'
//maybe you mean:: if (gr.name.toString().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 02:12 PM
Hi Tony,
I will stick with the UI Policy solution for now and wait and see what the testers will feedback.
Appreciate your help!
Ellie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 02:27 PM
Hi Tony,
I have tried it with: if (gr.name.toString() no difference.
//This gets you the NAME of the company :: gr. name --- Yes that is what I want the company's name from core_company tbl name field and then to check if it has ABB
I am of the understanding that var gr = new GlideRecord('core_company'); will return the complete row i.e all fields so thus I am using name field from the record set.
Cheers
Ellie