Mapping of catalog variables into fields of sc_req_item

Pushpanjali3
Tera Contributor

I need to map variables of catalog item into sc_req_item fields.

Requested for --> u_requested (reference to sys_user)

Location --> location

sc_category --> u_category_task 

Watch list --> watch_list 

Technician name --> work_notes_list 

Estimated end --> estimated_delivery 

Equipment --> cmdb_ci, configuration_item 


For this I'm using after insert business rule, but I couldn't achieve it. Here is the BR:

(function executeRule(current, previous /*null when async*/) {

// Check if the current RITM is being created or updated
    //if (current.variables.requested_for) {
        current.u_requested = current.variables.requested_for;

   // }
    if (current.variables.location) {
        current.location = current.variables.location;
    }
    if (current.variables.sc_category) {
        current.u_category_task = current.variables.sc_category;
    }
    if (current.variables.watch_list) {
        current.watch_list = current.variables.watch_list;
    }
    if (current.variables.technician_name) {
        current.work_notes_list = current.variables.technician_name;
    }
    if (current.variables.estimated_end) {
        current.estimated_delivery = current.variables.estimated_end;
    }
    if (current.variables.equipment) {
        current.cmdb_ci = current.variables.equipment;
        current.configuration_item = current.variables.equipment;
    }

    // Update the record
    current.update();
   
})(current, previous);




1 ACCEPTED SOLUTION

The Filter Condition should be fine.  Reference qualifiers don't matter when setting values via script.  I can see that the Request for variable is a reference type, but is the u_requested field also a reference type?  This is what has to match on each variable and field - so that you're not trying to populate a string value from a variable in a reference type field, etc.  To confirm this script is running and the variable values, these are the types of logs I was recommending, and removing the current.update() when switching the BR to before insert.  This will help narrow down if there is a conflict between variable type and field type:

 

(function executeRule(current, previous /*null when async*/) {
	gs.info('BR RITM running ' + current.number);
	gs.info('BR variable values ' + current.variables.requested_for + ' | ' + current.variables.location + ' | ' + current.variables.sc_category);
    current.u_requested = current.variables.requested_for;

    if (current.variables.location) {
        current.location = current.variables.location;
    }
    if (current.variables.sc_category) {
        current.u_category_task = current.variables.sc_category;
    }
    if (current.variables.watch_list) {
        current.watch_list = current.variables.watch_list;
    }
    if (current.variables.technician_name) {
        current.work_notes_list = current.variables.technician_name;
    }
    if (current.variables.estimated_end) {
        current.estimated_delivery = current.variables.estimated_end;
    }
    if (current.variables.equipment) {
        current.cmdb_ci = current.variables.equipment;
        current.configuration_item = current.variables.equipment;
    }
})(current, previous);

 

 

View solution in original post

5 REPLIES 5

No luck.

FYI

Pushpanjali3_0-1726678345647.png