when state change in progress and state change in on hold then on hold reason should be added

sangitakumari
Tera Contributor

Hi Team,

I have a requirement like when state change in progress and state change is on hold then on hold reason will be added in work notes and also when state is in progress then it also added in work notes. and also want to print in state value name and on hold value name. If anyone know Please let us know .

6 REPLIES 6

Hi @sangitakumari ,

 

I checked the same code in my pdi its working there was spelling mistake , please check below code 

 

(function executeRule(current, previous /*null when async*/ ) {
//gs.log("On hold reason: "+current.hold_reason);
    if (current.state == '2') {
        current.work_notes = "State changed to" + current.getDisplayValue('state');
    } else if (current.state == '3') {
        if (current.hold_reason == '3' || current.hold_reason == '4' || current.hold_reason == '5') {
            current.work_notes = "State changed to" + current.getDisplayValue('state') + "and reason is" + current.getDisplayValue('hold_reason');
            gs.log("work_notes chnage for state" + current.work_notes);
        }
    }

})(current, previous);

 

 

Result:

swathisarang98_0-1719388838557.png

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,

Swathi Sarang

MUDIGOLAMA
Tera Contributor

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

// Function to add text to work notes
function addToWorkNotes(note) {
current.work_notes = note;
gs.addInfoMessage(note);
}

// Check if the state is changed to 'In Progress' or 'On Hold'
if (current.state.changesTo('In Progress')) {
// Add to work notes that the state is 'In Progress'
addToWorkNotes('State changed to In Progress');
} else if (current.state.changesTo('On Hold')) {
// Check if there is an 'On Hold' reason provided
if (current.u_on_hold_reason != '') {
// Add to work notes the 'On Hold' reason
addToWorkNotes('State changed to On Hold: ' + current.u_on_hold_reason.getDisplayValue());
} else {
// Prompt user to provide an 'On Hold' reason
gs.addErrorMessage('Please provide a reason for putting the task On Hold.');
}
}

})(current, previous);