- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 07:02 AM
I am stuck at below script. Only first alert is shown and nothing happens. Short description is not copied too. Appreciate your advice.
function onLoad() {
//Type appropriate comment here, and begin script below
var parent1 = g_form.getDisplayBox('u_parent_ref').value;
alert(parent1); // this alert pop is working fine and nothing below this works!
var gr = new GlideRecord('u_agreement');
gr.addQuery('u_number', parent1);
gr.Query();
var temp = gr.u_short_description;
alert('in client script');
alert(temp);
g_form.setValue('short_description', temp);
}
Thanks in anticipation
Waseem
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 02:57 PM
If nothing works after your first alert then that would leave me to believe that maybe something is incorrect with the setup of your GlideRecord object. For instance what type of data type is parent1 holding? A number, string....etc. And what data type is u_number supposed to hold? Again a string or a number?
In other words does the data type match what type of data type the field is set to hold?
Also maybe use something other than "gr" as the variable name. Try something like grAgreement. I know your script is stuffed in an "onLoad" function however, "gr" in ServiceNow is used quite a bit and something else could be using the same in an onLoad client script on the same table. You never know. I've seen stranger things
You also have to remember that the Client Side GlideRecord is limited in functionality than the Server Side GlideRecord. Although this script doesn't seem too out of the ordinary.
I hope this helps.
Added comment:
Actually I see the issue is the uppercase Q in gr.Query. It should be gr.query()
I would also throw a check in there after querying highlighted in red.
ie:
var gr = new GlideRecord('u_agreement');
gr.addQuery('u_number', parent1);
gr.query();
if ( gr.next() ) {
var temp = gr.u_short_description;
alert('in client script');
alert(temp);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 02:57 PM
If nothing works after your first alert then that would leave me to believe that maybe something is incorrect with the setup of your GlideRecord object. For instance what type of data type is parent1 holding? A number, string....etc. And what data type is u_number supposed to hold? Again a string or a number?
In other words does the data type match what type of data type the field is set to hold?
Also maybe use something other than "gr" as the variable name. Try something like grAgreement. I know your script is stuffed in an "onLoad" function however, "gr" in ServiceNow is used quite a bit and something else could be using the same in an onLoad client script on the same table. You never know. I've seen stranger things
You also have to remember that the Client Side GlideRecord is limited in functionality than the Server Side GlideRecord. Although this script doesn't seem too out of the ordinary.
I hope this helps.
Added comment:
Actually I see the issue is the uppercase Q in gr.Query. It should be gr.query()
I would also throw a check in there after querying highlighted in red.
ie:
var gr = new GlideRecord('u_agreement');
gr.addQuery('u_number', parent1);
gr.query();
if ( gr.next() ) {
var temp = gr.u_short_description;
alert('in client script');
alert(temp);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2015 04:49 PM
Thank you Chris! it worked
issue was with mising gr.next()