When demand changes to another status, then 2 fields must be mandatory

Marielle Beset
Tera Contributor

Hello,

 

If a demand goes from Definition status to Qualified 2, the project manager and IT architect fields must be filled. I wanted to create a UI Policy for this in which I indicate that if status Definition changes in Qalified 2, the project manager and it architect fields are mandatory. However, I cannot enter a condition when status changes from .... to ...... in a UI policy.

If I create it in a business rule, I can indicate at When to run that status changes from ... to ...., but what do I put in the script?
I made a setup, but it doesn't work.

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

var gr = new GlideRecord('project_manager');
gr.addQuery('task', current.sys_id);
gr.query();
if (!gr.next()) {
current.setAbortAction(true);
gs.addErrorMessage('A project manager needs to be added before qualifying this demand.');
}

})(current, previous);

 

What is the best solution?

1 REPLY 1

yaswanthi2
Giga Sage

Hi @Marielle Beset 

you can try onChange client script by oldValue and newValue like below example

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
        return;
    }
    if (oldValue == 'software') { //assume that oldValue == definition and old Value, newValues are your onChange field name
        if (newValue == 'hardware') { // newValue == qualified
            g_form.setMandatory('description', true); // setMandatory of your required fields
        } else {
            g_form.setMandatory('description', false);
        }
    }
}