how to set reference field value using g_form.setValue();

Vasu20
Tera Contributor

In the UI action of sn_hr_core_case table an incident sys_id is recevied ,i need to set the received value to transferred_to field( reference field). I am using g_form.setValue('transferred_to',value) and it is not working.Any help is appreciated.

 

Thanks and Regards,

Vasu

1 ACCEPTED SOLUTION

then unless it's present in workspace view g_form cannot set the value

add that in your view and then verify

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

transferred_to field refers to HR Case table then how it can store the incident sysId

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

The transferred_to field refers to the Task table but it is present in the sn_hr_core_case table.

 

Thanks and Regards,

Vasu

Hi,

then it should work

please share all the script

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

function onClick(g_form) {

 

var incident_number = '';
g_modal.showFields({
title: "Please provide all information for incident",
fields: [{
type: 'textarea',
name: 'u_incidentreason',
label: 'Incident description:',
mandatory: true
}, {

type: 'reference', // type of modal (ie text, reference, etc)
name: 'assignment_group', // reference field on the current record used to search
label: 'Assignment Group', // message to display above the search field
mandatory: true, // sets the field to mandatory
reference: 'sys_user_group', // table that the reference field in "name" refers to
referringTable: 'incident', // table of the current record
referringRecordId: g_form.getUniqueValue(), // sys_id of the current record

}],
size: 'md'

}).then(function(fieldValues) {

 


var ga = new GlideAjax("sn_hr_core.hrTransferToInc");
ga.addParam("sysparm_name", "transferCase");
ga.addParam("sysparm_assignment_group", fieldValues.updatedFields[1].value);
ga.getXMLAnswer(saveForm);

 

function saveForm(result) {
g_modal.alert(result); //result value returns incident sys_id in string format

incident_number = result;
g_form.setValue('transferred_to',result);//not working
g_form.save();

 

}
});

}