Add a CI to an Incident

Tomas Linde
Tera Expert

Hello everyone, I have created several business rules based on this one to meet the requirements (when an Aloha Incident occurs. Assigned to field changes, the new value must be established in all affected CIs) but none of the ones I have worked correctly for me. created; I would appreciate your help, thanks in advance and greetings.

 

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

var assignedToAloha = current.task.assigned_to;

var ci = current.ci_item.getRefRecord();
if (ci.isValidRecord()) {
ci.assigned_to = assignedAAloha;
ci.update();
}

})(previous current);

5 REPLIES 5

Oya Orhan
Giga Guru

Hi @Tomas Linde 

Have you seen the bold underlined ones are not same in your code:

 

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

var assignedToAloha = current.task.assigned_to;

var ci = current.ci_item.getRefRecord();
if (ci.isValidRecord()) {
ci.assigned_to = assignedAAloha;
ci.update();
}

})(previous current);

 

If my post helped you, please click the accept solution button and hit the thumbs up! Thank you!

Oya

Sorry, it's an error when translating the text, the attached business rule does not meet the requirements of the story, since I need it to go through all the 'ci_item' and complete each of the AssingedTo fields of each of them.

 

Pranav_Thanedar
Mega Sage

Hi @Tomas Linde ,

 

Can you please try below changes to the code and check if those work?

 

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

var assignedToAloha = current.getValue('assigned_to');
var ci = current.ci_item.getRefRecord();

if (ci.isValidRecord()) {
ci.setValue('assigned_to',assignedToAloha);
ci.update();
}

})(previous current);

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.

 

Regards,

Pranav

This does not work because this part of the code (var assignedToAloha = current.task.assigned_to;) assigns to the variable the current value of the assigned to the task  table which is the intermediate reference table between the two tables.