How to get reference value from a reference variable?

tee3
Giga Expert

var ci = current.variables.cmdb_ci.getDisplayValue();

gs.log('CI' + ci);

if(ci)

{

var techSupport = ci.support_group;

gs.log('This is the support group' + techSupport);

task.assignment_group = techSupport;

}

else {

task.assignment_group = '9d7cbca24fb271007a990f5e9310c7e9';

}

I'm missing something fairly easy here, in the above code, my variable "techSupport" is always undefined. I'm using this script in the workflow activity to assign the task to a group based on the ci's support group(field named support_group on the ci form) if a ci is selected or assign to a defined group if its empty. The second part works. I cannot seem to get the value of the support group field for the ci on the item. I've tried getDisplayValue() with no luck.

Appreciate your help!

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Try this




  1. if(current.variables.cmdb_ci)  
  2. {  
  3. gs.log('This is the support group' + current.variables.cmdb_ci.support_group);  
  4. task.assignment_group = current.variables.cmdb_ci.support_group;  
  5. }  
  6. else {  
  7. task.assignment_group = '9d7cbca24fb271007a990f5e9310c7e9';  
  8. }  

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

Try this




  1. if(current.variables.cmdb_ci)  
  2. {  
  3. gs.log('This is the support group' + current.variables.cmdb_ci.support_group);  
  4. task.assignment_group = current.variables.cmdb_ci.support_group;  
  5. }  
  6. else {  
  7. task.assignment_group = '9d7cbca24fb271007a990f5e9310c7e9';  
  8. }  

Please mark this response as correct or helpful if it assisted you with your question.

I could swear that is what I started with and it didn't work so I started overthinking it but this worked like a charm! Thanks!



Any insight as to why this works without getting the display value of the ci?


We don't need display value since we are just going to use dotwalking concept to get the glide values of the cmdb-ci reference field. display value will give the name of the CI and i think using that it won't help us to access the gliderecord of the same field instead of with sys_id of the CI.


Agree with Shishir. You dont need display value to get to the sys id. you can just dot walk to the field and use it.



Please mark this response as correct or helpful if it assisted you with your question.