How to implement an Alert in Change Request?

Meera_P
Tera Expert

Hi,

How to implement an Alert in Standard Change Request only when state changes to "Implement"?

I need to reminder the requestor to add an attachment.  Thank you

 

 

Meera_P_0-1711603485691.png

 

15 REPLIES 15

@Meera_P  : The sys id of the attachment would differ each time when its uploaded.

 

If you want to validate if an attachment exists definitely you need to glide the table and check it which can be done using GlideAjax and get the response in Client script. 

 

But my concern on this attachment is "How will you identify if that's the correct attachment?" because a record might have one or more attachments but the record remains the same. 

 

If its incorrect, you will remove and add it manually. Kindly have those use cases tested. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Thank you @Sujatha V M 

We are concerned if there is an attachment in the record. If the attachment is incorrect, we will inform the user to reattach the correct file. I will implement your suggestion of using GlideAjax.

 

I am still learning scripting, so there may be instances where my questions are unclear or lack coherence. 

 

Once the response back from the GlideAjax shows there are no attachments.

Is it possible to call the UI Page (Attachment) after Alert so that users can attach the file?

 

Meera_P_0-1711608995730.png

 

@Meera_P  Good that you take effort to try out! Keep up the good work. That's how I'm also learning. 

 

You can keep your customizations limited and use appropriate syntaxes which haven't deprecated or break the existing or affects the instance performance. 

 


Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

@Sujatha V M 

Please help review the code and let me know where I screwed it up, because it is not working.  Thank you

 

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var stateStatus = g_form.getValue('state');
    if (stateStatus == '-1') { // Implement State
        var ga = new GlideAjax('chg_GetAttachment');
        ga.addParam('sysparm_name', 'getFile');
        ga.addParam('sysparm_attachment', g_form.getUniqueValue);
        ga.getXMLAnswer(checkAttachment);

        function checkAttachment(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            alert(answer);
        }
    }
}
 
Script Includes:
var chg_GetAttachment = Class.create();
chg_GetAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getFile: function() {
        var chgSysId = this.getParameter('sysparm_attachment');
        var attachment = new GlideRecord('sys_attachment');
        attachment.addQuery('table_name', 'change_request');
        attachment.addQuery('table_sys_id', chgSysId);
        attachment.addQuery('type', 'standard');
        attachment.query();
        var result = {};
        if (!attachment.next()) {
            result.message = "Attachment is required; please include the attachment.";
        }
        return JSON.stringify(result);
    },
    type: 'chg_GetAttachment'
});
 
 

@Meera_P  : If I comment out this line, 

 

SujathaVM_0-1711613017773.png

 

Output : 

SujathaVM_1-1711613053999.png

If I add that line, 

SujathaVM_2-1711613084362.png

Seems that "type" is from change request and not from sys_attachment table. Only "Content type" field is available in attachments so its not query the records. 

SujathaVM_3-1711613231945.png

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.