I need to close the PTASK based on some conditions

shivani_jamdade
Tera Contributor

I need to implement the functionality to close the PTASK based on the fields of the form in Closure Tab Realted List to validate if Training date is past date, Change is in reviewed or closed state and then only close the PTASK.

Please help me with the script.

Thanks!

2 REPLIES 2

GlideFather
Tera Patron

Hi @shivani_jamdade 

it could be client script onSubmit, or a flow.

 

You should draft something and share your blockers, not assign others with your task 😛 for learning purposes it's better to at least try it yourself not wait until somebody else does it for you... what do you think about it?

 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


For your information I have already tried with Client Script but it doesnt work. If you dont want to help please avoid to comment.

 

for your reference

function onSubmit() {
   //Type appropriate comment here, and begin script below
   // Get the sys_id of the related Change Request
    var changeSysId = g_form.getValue('u_change_number'); // Replace with your field name!

    if (changeSysId) {
        var ga = new GlideAjax('CheckChangeState');
        ga.addParam('sysparm_name', 'isChangeReviewedOrClosed');
        ga.addParam('sysparm_change_sys_id', changeSysId);

        ga.getXMLAnswer(function(response) {
            var isValid = response;

            if (isValid === 'false') {
                alert('The associated Change Request must be in Reviewed or Closed state before closing this Problem Task.');
                g_form.submitted = false; // block submit
            } else {
                g_form.submit(); // proceed with submit
            }
        });

        return false; // block submit until callback returns
    }

    return true; // no change linked — allow submit
}