Get change request details to populate form

rhysbrennan
Tera Expert

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.

1 ACCEPTED SOLUTION

Updated the script



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

11 REPLIES 11

Prateek kumar
Mega Sage

Isn't your script should be onchange. I am guessing that when ever you want to populate a reference Change number, you are expecting your query to populate all the details that are related to that CR.


If this is the case, try following. I cannot copy my script in here. PFA



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Thank you. I tried to use this but unfortunately nothing populates.



I think the issue is the g_form.getValue but I'm not sure. Because the g_form.getValue returns the Change Number i'm thinking the script include won't work because it's looking for the sys_id.


try replacing this line in your script include



detailsRec.addQuery('number', change);


That worked, but I've come across the next issue. The "answer" is a comma delimated string, but the script script uses the variable "answers" which isn't defined. So I change the alert to Answer and got the state back, but non of the other fields came back.



Details are in the attachement.



Side note, why can't we paste scripts or pictures anymore in the community?


Updated the script



Please mark my response as correct and helpful if it helped solved your question.
-Thanks