The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Different Demand Assessments for Stakeholders Business Rule Help

Laurie Marlowe1
Tera Guru

Hello,

This is a Demand question on the Create OnDemand Assessment   business rule.   I recently posted a similar question about sending different stakeholders different assessments:

We are setting up Demand, and want our Business Stakeholders to receive "Assessment A", and our IT people to receive "Assessment B".   Is there a way to do this out of box that I am missing?   I know how to accomplish this via a customization, but before I do that I wanted to check and see if there is an out of box configuration to do this.

The answer I got was there is nothing out of the box that does this, so I will need to modify the business rule.   So, this is what I did:

  • Added a column to the Stakeholder Register table called Assessment Type (u_assessment_type).   Choices are "Risk" and "Business Value Scorecard"

Capture.JPG

  • For each stakeholder I specified which assessment they should receive.   Risk goes to IT, and Business Value Scorecard goes to the Business.   We want both assessments to be created when the state is changed to Screening.
  • I updated the business rule to try to send the different assessments.   I tried various "things" and cannot seem to get the business rule to recognize the assessment type.   Could this be due to the table being used in the business rule being an m2m?  

gs.addInfoMessage('Assessments Created');

var gr = new GlideRecord('dmn_m2m_demand_stakeholder');

var encodedQuery = "demand=" + current.sys_id + "^stakeholder.assessment=yes";

gr.addEncodedQuery(encodedQuery);

gr.query();

var userIds = "";

while (gr.next()) {

  if (!JSUtil.nil(userIds))

  userIds += ",";

  userIds += gr.stakeholder.user.sys_id;

  gs.addInfoMessage('userId ' + userIds);

  gs.addInfoMessage('user ' + gr.stakeholder.user);

  gs.addInfoMessage('type ' + gr.stakeholder.u_assessment_type); //sometimes this shows the type and sometimes it does not

}

if (!JSUtil.nil(userIds) && (gr.stakeholder.u_assessment_type = 'bvs')){

  //create Business Value Score assessments for the list of users

  (new SNC.AssessmentCreation()).createAssessments('0556fa9a8f12110040f82ab2f0f923f8', current.sys_id, userIds, false, "");

} else if (!JSUtil.nil(userIds) && (gr.stakeholder.u_assessment_type = 'risk')){

  //create Risk assessments for the list of users

  (new SNC.AssessmentCreation()).createAssessments('a150471e6ff622004c3e841dba3ee407', current.sys_id, userIds, false, "");

}else{

  //make sure to generate the ondemand assessments for the case where there are no stakeholders

  //bvs

  (new SNC.AssessmentCreation()).createAssessments('0556fa9a8f12110040f82ab2f0f923f8',current.sys_id, gs.getUser().getRecord().getValue("sys_id"), false, "");

  //risk

  (new SNC.AssessmentCreation()).createAssessments('a150471e6ff622004c3e841dba3ee407',current.sys_id, gs.getUser().getRecord().getValue("sys_id"), false, "");

}

Based on the messages, I can tell the Assessment Type is being read, so why isn't my "if" statement working?   All the stakeholders are getting the Business Value Scorecard.   One stakeholder should be getting the Risk assessment.

Capture1.JPG

Please and thank you in advance!

Laurie

9 REPLIES 9

nitish99
Mega Guru

Hey Laurie,



The problem is in the if condition, instead of checking you are assigning value to Assessment Type. Same issue in the else if condition.



Do modify the code as such -:



  1. if (!JSUtil.nil(userIds) && (gr.stakeholder.u_assessment_type == 'bvs')){  
  2.   //create Business Value Score assessments for the list of users  
  3.   (new SNC.AssessmentCreation()).createAssessments('0556fa9a8f12110040f82ab2f0f923f8', current.sys_id, userIds, false, "");  
  4.  
  5. } else if (!JSUtil.nil(userIds) && (gr.stakeholder.u_assessment_type == 'risk')){  
  6.  
  7.   //create Risk assessments for the list of users  
  8.   (new SNC.AssessmentCreation()).createAssessments('a150471e6ff622004c3e841dba3ee407', current.sys_id, userIds, false, "");  
  9.  
  10. }

Hey Nitish,



Thank you for your response!   I can't believe I did that!   Anyway, it did not fix my original issue of how to generate two different assessments based on Assessment Type field.   Any ideas on that?   I'm thinking it has to do with a filter on the metric category or metric type fields.



Thanks,



Laurie


Hey Laurie,

After the code I just saw your query "why isn't my "if" statement working?" (felt sleepy @ the moment). Apologies for the same.

Could you try tweaking your code as follows -:


  1. if (!JSUtil.nil(userIds){  
  2.   if (gr.stakeholder.u_assessment_type = 'bvs'){
  3.   //create Business Value Score assessments for the list of users  
  4.   (new SNC.AssessmentCreation()).createAssessments('0556fa9a8f12110040f82ab2f0f923f8', current.sys_id, userIds, false, "");  
  5.   }
  6.   if (gr.stakeholder.u_assessment_type = 'risk'){
  7.   //create Risk assessments for the list of users  
  8.   (new SNC.AssessmentCreation()).createAssessments('a150471e6ff622004c3e841dba3ee407', current.sys_id, userIds, false, "");  
  9.   }
  10. }
  11. else{  
  12.   //make sure to generate the ondemand assessments for the case where there are no stakeholders  
  13.   //bvs  
  14.   (new SNC.AssessmentCreation()).createAssessments('0556fa9a8f12110040f82ab2f0f923f8',current.sys_id, gs.getUser().getRecord().getValue("sys_id"), false, "");  
  15.   //risk  
  16.   (new SNC.AssessmentCreation()).createAssessments('a150471e6ff622004c3e841dba3ee407',current.sys_id, gs.getUser().getRecord().getValue("sys_id"), false, "");  
  17. }

Hi Nitish - I think figured out the issue and it's not with the business rule.   I opened a ticket with ServiceNow just to be sure of what I think the issue is.   I will post a response when I get one.



I appreciate your help!



Laurie