Need to update attachment field after raising the request

bharathvall
Kilo Contributor

As a requester,

 

I want the attachment added field in the RITM (sc_req_item) record to automatically display the number of attachments uploaded when submitting a catalog item request with a mandatory attachment,

So that the request record clearly reflects how many documents were attached at the time of submission.

please find the below screenshots,

bharathvall_0-1758005617388.png

 

 

bharathvall_1-1758005641866.png

Below I write the business rule:

var WhatOperation = current.operation();
    var ForWhom = current.table_sys_id;
    var ParentREQ = '';
    var ChildWho = '';

    // For insert action
    if (WhatOperation == 'insert') {

        var GRITMAdd = new GlideRecord('sc_req_item');
        GRITMAdd.addQuery('sys_id', '=', ForWhom);
        GRITMAdd.query();
        if (GRITMAdd.next()) {
            var UpdateAdder = GRITMAdd.u_attachment_added;
            UpdateAdder++;
            GRITMAdd.u_attachment_added = UpdateAdder;
            ParentREQ = GRITMAdd.request;
            ChildWho = GRITMAdd.number;

            GRITMAdd.update();

        }
        // Updating REQ also - Why? FlowDesigner challenge for sc_req_item table
        var GREQAdd = new GlideRecord('sc_request');
        GREQAdd.addQuery('sys_id', '=', ParentREQ);
        GREQAdd.query();
        if (GREQAdd.next()) {
            var UpdateAdderREQ = GREQAdd.u_attachment_added;
            UpdateAdderREQ++;
            GREQAdd.u_attachment_added = UpdateAdderREQ;
            GREQAdd.u_updated_ritm = ChildWho;

            GREQAdd.update();

        }

    }
    // For delete action
    else if (WhatOperation == 'delete') {

        var GRITMDel = new GlideRecord('sc_req_item');
        GRITMDel.addQuery('sys_id', '=', ForWhom);
        GRITMDel.query();
        if (GRITMDel.next()) {
            var DeleteAdder = GRITMDel.u_attachment_deleted;
            DeleteAdder++;
            GRITMDel.u_attachment_deleted = DeleteAdder;
            ParentREQ = GRITMDel.request;
            ChildWho = GRITMDel.number;

            GRITMDel.update();
        }


        // Updating REQ also - Why? FlowDesigner challenge for sc_req_item table
        var GREQDel = new GlideRecord('sc_request');
        GREQDel.addQuery('sys_id', '=', ParentREQ);
        GREQDel.query();
        if (GREQDel.next()) {

            var UpdateDelREQ = GREQDel.u_attachment_deleted;
            UpdateDelREQ++;
            GREQDel.u_attachment_deleted = UpdateDelREQ;
            GREQDel.u_updated_ritm = ChildWho;
            GREQDel.update();

'        }
 
it is not working when user requested raise RITM, it is not updating in "Attchment_added" field,
the root cause is:
when an attachment is added to the catalog item, the attachment table sys_id is different from the one creating after submitting the request, That's why it is not being captured the first time
 
Before submiting:
 
bharathvall_2-1758006107012.png

IN Attchment table:

bharathvall_3-1758006182991.png

 

After submitting:

bharathvall_4-1758006282951.png

After submiting RITM sys_id noth same.

 

can you help me for this issue.

0 REPLIES 0