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.

How to populate record producer field in incident table on creation of new items in table?

Kiran_25
Tera Expert

Hi

Currently when an incident is created, the name of the record producer only goes into the Record Producer field in the Incident table overnight via a Scheduled Script Execution.

I want to make that happen when the Incident is created, what would be the best way to do this? 

 

Can the Scheduled Script be set to run when a new incident is created? There is also a script include that runs in the background.  

3 REPLIES 3

Sid_Takali
Kilo Patron

Hi @Kiran_25 You can use Record Producer Script field to map a Record Producer field to Incident Field. 

 

Regards,

Siddharam

Hi

This is the script currently:

 

var caller = gs.getUserID();
var parent_table = RP.getParameterValue('sysparm_parent_table');
if (JSUtil.notNil(parent_table)) {
    var parent_map = new GlideRecord('request_parent_mapping');
    parent_map.addQuery('parent_table', parent_table);
    parent_map.query();
    if (parent_map.next())
        var requested_for_field = parent_map.getValue('requested_for_field');
    var parentGR = new GlideRecord(parent_table);
    parentGR.addQuery('sys_id', RP.getParameterValue('sysparm_parent_sys_id'));
    parentGR.query();
    if (parentGR.next())
        caller = parentGR.getValue(requested_for_field);
}
current.contact_type = 'virtual_agent';
current.caller_id = caller;
if (producer.comments.length > 80)
    current.short_description = producer.comments.substring(0, 79);
else
    current.short_description = producer.comments;
current.description = producer.comments;

var incRPUtil = new LinkRecordProducerToIncident();
incRPUtil.linkRecordProducerToParentIncident(RP.getParameterValue('sysparm_parent_sys_id'), current);


Ramz
Mega Sage

Hi @Kiran_25 ,

You can do a after insert business rule on incident table:

sc_item_produced_record table stores the names of record producer

var gr = new GlideRecord("sc_item_produced_record");
gr.addQuery("task", current.sys_id);
gr.query();
if (gr.next()) {
	current.record_producer = gr.producer.sys_id;//your record producer variable name
	current.update();
}

Please mark my answer correct/helpful if it resolved your query