Make Risk Assessment on Change Mandatory

tom_hs2
Kilo Contributor

Hi All,

 

i have recently installed the Change Risk Assessment Plugin. This appears as a related link on the change form. I have set conditions so once taken, it will auto set the Risk for hat change. I wish to make taking the risk assessment mandatory before you can move to the assess phase. I have used the following scripting

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if (isLoading || newValue === '') {


return;


}


var changeNumber = g_form.getUniqueValue();


var changeType = g_form.getValue('type');

 

//If state changes from New to Assess check if there is a risk assessment


if((newValue == -4) && (oldValue == -5) && (changeType == 'normal')) {

 

var gr = new GlideRecord('task_assessment');


gr.addQuery('task', changeNumber);


gr.query();


if(gr.next()){


g_form.addInfoMessage('Risk Assessment has been completed');


return;


}


else{


g_form.addErrorMessage("Risk Assessment needs to be completed before requesting approval. Use the Risk Assessment link under Related Links");


g_form.setValue('state',-5); //Set state to New


return;


}


}


}

 

This as intended stops the requester from moving to assess phase (when they click the request approval button). It also shows an error message advising they need to take the Risk assessment.

The issue i have, that even when the user has taken the risk assessment, it still does not allow the change to move to the assess phase after requesting approval. It says the same error message - "Risk Assessment needs to be completed before requesting approval. Use the Risk Assessment link under Related Links" even though the usr has taken one.

 

any ideas how i can get this to work?

4 REPLIES 4

vinothkumar
Tera Guru

Add return false in your else statement, which will stop from processing.

 

else{


g_form.addErrorMessage("Risk Assessment needs to be completed before requesting approval. Use the Risk Assessment link under Related Links");


g_form.setValue('state',-5); //Set state to New


return false; // Add false


}

Thanks for the response but still does not work. My issue is that it'snot processing to the next phase after a risk assessment has been taken.

when the end user hits request approval, it should go to the next phase (from new to assess). The idea is that if the end user hasn't done a risk assessment for this change, it will not let them go to the next phase. If they have done one it will. Issue is that even when the end user has completed a risk assessment, it is still not letting them go to the next phase.

Hello Tom, You can create some custom field named risky as checkbox field and once the user filled that risk assesment, then update that field to true and do your logic in the business rule that when state changes from so and so and risk is empty use gs.addInfoMessage("change can't be moved with out filling risk"); And use current.setAbortAction(true); to abort the form submission.

That sounds better logic,

 

how would the scripting look for the business rule? I'm struggling with that bit