Formatter

Reena Kumari2
Tera Contributor

Hi Team,

 

Can we call formatter on case form and make it mandatory as per assignment group changes?

 

Thanks & Regards,

Reena

10 REPLIES 10

Hi Ankur,

 

This formatter thing somehow I sorted but the thing is like whenever the assignment group changes the digital signature is required on case form . I implemented the logic using script include and onsubmit client script. But I am stuck at one point. First time it asks for digital signature , if I select the have you signed field as no. But 2nd time it doesn't ask , it saya signature found.

Below are my script include and client script code-

 

Script include:-

var CheckSignatureAttachment = Class.create();
CheckSignatureAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    hasSignatureAttachment: function() {
        var caseId = this.getParameter('sysparm_case_id');
        if (!caseId) {
            return "Error: No case ID provided";
        }

        var attachmentGR = new GlideRecord('sys_attachment');
        attachmentGR.addQuery('table_sys_id', caseId);
        attachmentGR.addQuery('content_type', 'image/png'); // Assuming signature is PNG
        attachmentGR.orderByDesc('sys_created_on');
        attachmentGR.query();

        if (attachmentGR.next()) {
            return "Signature found";  // Signature exists
        } else {
            return "No signature found";  //  No signature attached
        }
    },

   

    isPublic: function() {
        return true; // Allow client-side GlideAjax calls
    }
});
 
 
Client script:-
function onSubmit() {
    var signed = g_form.getValue('u_have_you_signed'); // Ensure the correct field name
    var caseId = g_form.getUniqueValue(); // Get the record ID

    if (signed == 'No') { // If user selects "No", check for signature
        var ga = new GlideAjax('CheckSignatureAttachment');
        ga.addParam('sysparm_name', 'hasSignatureAttachment');
        ga.addParam('sysparm_case_id', caseId);

        g_form.addInfoMessage("Checking for digital signature...");

        ga.getXMLAnswer(function(response) {
            //g_form.clearMessages(); // Remove old messages
            alert(response);

            if (!response || response.trim() == "No signature found") {
               // g_form.addErrorMessage("A digital signature is required before submitting.");
                alert("You must provide a digital signature.");
                return false; //  Prevent submission
            } else {
                g_form.addInfoMessage("Signature verified, proceeding with submission.");
                //g_form.submit(); //  Allow submission
            }
        });

        return false; // Prevent form submission until check is complete
    }

    return true; // Allow submission if "Yes" is selected
}

@Reena Kumari2 

don't use onSubmit as by the time script include function checks the form will be submitted a syou are using Asynch GlideAjax.

Please use before update business rule.

Also ensure you query sys_attachment with the file name as well or else your logic will simply check if any image is present.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Reena Kumari2 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Reena Kumari2 

I don't think you can make it mandatory.

What you can do is validate using before update business rule if Assignment group changes then an entry is made into signature table for your current record

If not then abort the update.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader