How to get CI service owner and requester's manager as approver in workflow approval activity

srikanth241
Mega Expert

Hi All,

How to get CI service owner and requester's manager   as approvers   in workflow approval activity for a catalog Item.

Catalog Item has application variable which captures CI's and employee variable for requester.

If CI's service owner is missing then it should check for service category owner , if that is also blank then it should check Service Executive. All these are fields in cmdb_ci table.

find_real_file.png

Any suggestion or code assistance will help me a lot.

thanks

PlatformDeveloper CommunityDeveloper CommunityDiscussDevelopCommunity Corner

1 ACCEPTED SOLUTION

Thanks Chuck! It's working



Here is the final code!



function getServiceOwner(){


  var user = new GlideRecord('cmdb_ci_appl');


  if(user.get(current.variables.application)){


  if (!user.managed_by.nil()) {


  //gs.log("manger" + user.managed_by );


  answer.push(user.managed_by);


  } else if (!user.owned_by.nil()) {


  answer.push(user.owned_by);


  //gs.log("owner" + user.owned_by );


  } else {


  answer.push(user.u_service_executive);


  //gs.log("service owner" + user.u_service_executive);


  }


  }


}


View solution in original post

12 REPLIES 12

srikanth241
Mega Expert

any suggestion or help, It's little bit urgent.


ctomasi


dvp


Developer Community


In your getServiceOwner() function, double check the value of current.variables.application to ensure it's not empty/null. Your user.get() may be failing and you don't know it.



Example:



if (! current.variables.application) {


        gs.log('No application specified');


        return;


}



if (!user.get(current.variables.application)) {


        gs.log('uh-oh, no application retrieved for: ' + current.variables.application);


        return;


}



// Now you can look at getting at the user-dot properties here...


Hello Chuck,



Thanks for your response.


Now I am getting log   as NT2 undefined.



Which means as it is reference field in CI table should I need to use getDisplay value..? or is there any mistake in my code..?


user.u_service_executive;


user.u_service_executive



My function:


function getServiceOwner(){


  gs.log("nithin");


  var user = new GlideRecord('cmdb_ci');


  if(user.get(current.variables.application)){


  if (!user.managed_by.nil()) {


  gs.log("NT" + user.managed_by );


  answer.push(user.managed_by);


  } else if (!user.owned_by.nil()) {


  answer.push(user.owned_by);


  gs.log("NT1" + user.owned_by );


  } else {


  answer.push(user.u_service_executive);


  gs.log("NT2" + user.u_service_executive );


  }


  }


}



Thanks.


This sounds like the u_service_executive field may be on a sub-class of cmdb_ci and not on cmdb_ci directly. Check the dictionary entry for that field to determine which field it is on. This is a common mistake on hierarchical tables.


Exactly Chuck , It is a subclass of cmdb_ci. So what is the way to get that value into approval array in workflow chuck?


find_real_file.png


Any Suggestion will help a lot


Thanks.


AB