- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 06:31 PM
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:
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 ?
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 06:44 PM
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);
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 06:44 PM
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);
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 07:09 PM - edited 08-16-2023 07:12 PM
Hi @AnveshKumar M ,
Thanks for coming back to me but this didn't work, the value is blank and is not even appearing now on double click of the variable name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 07:31 PM
Have you checked the system logs for this message "Didn't found CI with given name"?
Create a new request and check the task, if there is any CI available in cmdb it should be visible in task form otherwise you should see the message "Didn't found CI with given name" in system logs.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 06:46 PM - edited 08-16-2023 06:53 PM
Why not use flow designer to accomplish this? You can take whatever then entered in the field and populate the reference field on the Task without breaking a sweat, you can add error handling directly in the flow aswell
your also relying on the end user to enter the correct information,
Mark ✅Correct if this solves your issue and also mark 👍Helpful if you find my response helped in any way