Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

replace as this line.



retVal = detailsRec.getValue('state') + ',' + detailsRec.getValue('planned_start') + ','+ detailsRec.getValue('planned_end') + ',' + detailsRec.getDisplayValue('change_owner') +' ,' + detailsRec.getDisplayValue('change_assignee');


Thank you both. It helped me to find the solution. In the end it didn't help that I didn't realised the variables in the script include were dummys.



retVal = detailsRec.state.getDisplayValue() + ',' + detailsRec.start_date + ',' + detailsRec.end_date + ',' + detailsRec.u_change_owner.getDisplayValue() + ' ,' + detailsRec.assigned_to.getDisplayValue();



Thanks again!