- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 02:58 PM
Hi,
I'm at a loss here on how to get details for an existing change request to populate a SC or SP form.
The form has a two fields at the moment just to get started, and the form hinges on a qualified reference to the change_request table.
I will need to return the change's:
-State
-Planned Start
-Planned End
-Change Owner
-Change Assignee
-Change Task
Ideally if I can get a start I'll capture most of the above for the change task if it exists.
This is the current attempt to return anything related to the change request populated through a client script:
function onLoad() {
var tochange = 'ChangeState';
var varchange = g_form.getValue('Change') ;
alert(varchange); //returns the Change
var gr = new GlideRecord('change_request');
gr.get('varchange'); //trying to get the Change Request details
alert(gr.state); //return the state??
alert(gr.number); //return the number the same as varchange ??
g_form.setValue('tochange',gr.state); //set the ChangeState form field to the requests State.
}
The first alert works showing the change number.
The second alerts return 'undefined'
Any helps appreciated. I'm hoping to get away with a GlideRecord call but if I have to do something different I'm open to suggestions.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 07:50 PM
Updated the script
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 03:24 PM
please like try below, for testing purpose you can try that but it's not recommended to have the glide query in client script instead you can use glideajax call (script include) to fetch the data from server side.
function onLoad() {
var tochange = 'ChangeState';
var varchange = g_form.getValue('Change') ;
alert(varchange); //returns the Change
var gr = new GlideRecord('change_request');
if(gr.get('number', varchange)){
alert(gr.state);
alert(gr.number);
}
g_form.setValue('tochange',gr.state); //set the ChangeState form field to the requests State.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 06:47 PM
Hi Shishir,
Unfortunately it didn't populate the form. The second alerts don't appear either so the 'if' statements not returning true.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var tochange = 'ChangeState';
var varchange = g_form.getValue('Change') ;
alert(varchange); //returns the Change
var gr = new GlideRecord('change_request');
if(gr.get('number', 'Change')){
alert(gr.state);
alert(gr.number);
}
g_form.setValue('tochange',gr.number); //set the ChangeState form field to the requests State.
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 06:53 PM
what value does change has in if(gr.get('number', 'Change')) line?? it should be varchange if var varchange = g_form.getValue('Change') ; gives change number.
please try with
if(gr.get('number', varchange)){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 07:18 PM
Sorry that was me trying to eliminate the problem.
I used if(gr.get('number', 'Change') to see if I could use the reference field without declaring it. I used if(gr.get('number', varchange ) as you suggested. The second lot of alerts do not populate after the if statement.