Auto populate a reference variable with user input from a text field

A Kose
Tera Contributor

I have a request to auto populate a reference field on the Task form of a requested item, with user input from a single line text variable on a Catalog Item.

I created a BR on the catalog task table. 

When to Run: before Insert, Order: 100, Filter Conditions: request item.item = abc

Advanced: 

(function executeRule(current, previous /*null when async*/) {
if(current.variables.action == 'new') //is new ict is selected
{
current.cmdb_ci = current.request_item.variables.name; //user inserts text into the name variable
}
else //if modify existing ict 
{
current.cmdb_ci = current.request_item.variables.ict_system_name; //select from look up
}
})(current, previous);

 

When I go to the task it doesn't auto populate the cmdb_ci field and there is no preview available for this variable: 

AKose_2-1692061996722.png

 

 

BUT when I double click on the variable name I get this, so the value which the user input 'debug' is there but just not populating the reference field ?

AKose_1-1692061910246.png

if I click ok it will populate the value into the field and then I can preview information via the 'i'. 

The record is created in the cmdb table and I can see it. 

Has anyone experienced this? 

I have tried a few ways to do this but none were successful. I feel it should be pretty straight forward and easy but I just can't get it. Any advice?

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @A Kose ,

You need to pass sys_id to reference fields, you can try like this.

 

if(current.variables.action == 'new') //is new ict is selected

{

var gr = new GlideRecord("cmdb_ci");

if(gr.get("name", current.request_item.variables.name)){

 current.cmdb_ci = gr.getUniqueValue(); //user inserts text into the name varible

}else{

  gs.info("Didn't found CI with given name");

}

}

else //if modify existing ict 

{

current.cmdb_ci = current.request_item.variables.ict_system_name;//select from lookup

}

})(current, previous);

 

Thanks,
Anvesh

View solution in original post

6 REPLIES 6

Hi Wizard,

I will have a look at this, thanks. 

Hey__ DC, there is currently a workflow in place for this catalog item so I can't add a flow as this workflow is required to run. So I'm not sure how this will work