Create Enhancement UI Action in Demand

Tony K
Kilo Sage
Kilo Sage

I was looking at updating the UI action to create an enhancement from a demand record to prepopulate fields. In looking at this particular UI action though, this looks like no other UI action that I've used before. It doesn't have any of the regular lines like task.description = current.description;

My question where do you specify what fields to auto fill in on the enhancement with info from the demand?

This is our OOB create enhancement UI on the demand table.

if( current.type == 'enhancement' ){

var demandUtil = new AjaxCreateRelatedEntityFromDemand();

var resultAsObject = true;

var enhancementObj = demandUtil.createEnhancement(current.sys_id, resultAsObject);

var enhancementId = enhancementObj.sys_id;

var number = enhancementObj.number;

var displayLabel = enhancementObj.label;

var enhancement;

var message;

var link;  

if (enhancementId) {

enhancement = new GlideRecord('rm_enhancement');

enhancement.addQuery("sys_id", enhancementId);

enhancement.query();

if(enhancement.next()){

link =' <a href ="/rm_enhancement.do?sysparm_query=number%3D' + number + '">'+ number +'</a>';

message = gs.getMessage("{0} {1} has been created");

message = message.replace("{0}", displayLabel);

message = message.replace("{1}", link);

gs.addInfoMessage(message);

}

} else {

message = gs.getMessage("Error creating {0}");

message = message.replace("{0}", displayLabel);

gs.addErrorMessage(message);

}

action.setRedirectURL(current);

}

1 ACCEPTED SOLUTION

Justin Abbott
Giga Guru

Inside the createEnhancement method of the AjaxCreateRelatedEntityFromDemand Script Include. Lines 30 and 31 are using setValue to set the short_description and parent, as examples.


View solution in original post

3 REPLIES 3

Justin Abbott
Giga Guru

Inside the createEnhancement method of the AjaxCreateRelatedEntityFromDemand Script Include. Lines 30 and 31 are using setValue to set the short_description and parent, as examples.


guess that was easy. Just used to looking at UI actions that had everything right in the action and reference a script include.   Is there any harm in updating this script include to prepopulate more fields? it will get missed in future updates as we've changed it from OOB?


You could always "extend" the Script Include and write your own version of the existing methods, in order to safeguard the OOB code.



Here's a link to the developer training site, which explains how to extend a Script Include.



https://developer.servicenow.com/app.do#!/training/article/app_store_learnv2_scripting_istanbul_serv...