After the attachment attached in the RITM form it should create sc_task

Gayathree Seeth
Tera Expert

Hi,

When ITIL user changes the Approval field in the RITM form as approved then it should ask for the mandatory attachment in the Ritm form and then only the catalog tasks should be created.

 

Here, changing of the approval field is done using the ACL can you please suggest how that attachment can be made mandatory before creation of SC_task.

 

Thanks in Advance!!

2 ACCEPTED SOLUTIONS

Hi @Gayathree Seeth,

So as stated earlier for this you need to have client script as well as script include.

Client Script :

JohnsMarokky_0-1681148247708.png

 

var approval = g_form.getValue('approval');
if(approval == 'approved'){    
var attachmentGA = new GlideAjax('checkForAttachment');
    attachmentGA.addParam('sysparm_name', 'checkAttachment');
    attachmentGA.addParam('sysparm_record_sysId', g_form.getUniqueValue());
    attachmentGA.getXMLWait();
    var attachmentNotExist = attachmentGA.getAnswer();
    if (attachmentNotExist == 'true') {
        alert("Madatory attachment Not added and the record will not be saved. Refreshing the page");
        location.reload();
        return false;
    }
}

 

 

Script Include:

JohnsMarokky_1-1681148356950.png

 

checkAttachment: function() {
		
        var recordSysId = this.getParameter('sysparm_record_sysId');
        var attachmentNotExist = false;
        var attachmentGr = new GlideRecord('sys_attachment');
        attachmentGr.addQuery('table_sys_id', recordSysId.toString());
        attachmentGr.query();
        if (!attachmentGr.next()) {
            attachmentNotExist = true;
        }
        return attachmentNotExist;
    },

 

 

Hope this helps.

 

Mark helpful and accept the solution if it helps in Solving your query.

 

Regards,

Johns

View solution in original post

Hi @Gayathree Seeth,

if you use attachmentGr.getRowCount(); after attachmentGr.query(); in the script include it will give you the attachment count.

 

Mark helpful if it helps in solving your query.

 

Regards,

Johns

View solution in original post

10 REPLIES 10

Johns Marokky
Tera Guru

Hi @Gayathree Seeth .

I think you can create an onSubmit script to make sure that the attachment is added.

I think you can follow the below support article which might help you.

How to enforce "mandatory" requirement on an attachment field - Support and Troubleshooting (service...

 

Hope this is helpful.

Mark helpful if it helps in Solving your query.

 

Regards.

Johns

Hi Johns,

Thanks for the reply.

I used Onsubmit client script with the below code:

function onSubmit() {
//Type appropriate comment here, and begin script below
//Get the field
if (approval==approved)
{
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_req_item");
gr.addQuery("sys_created_by", g_user.userID);
gr.query();
if (!gr.next())
{
alert("Please attach the Required Document to proceed with submitting.");
return false;
}

}
}

After using this code i am getting this error attached below

GayathreeSeeth_0-1681029005473.png

My requirement is when i am changing the approval field as approved it should ask for the mandatory attachment and then only i will be able to submit the RITM form.

 

Please suggest the code for this scenario.

Gayathree Seeth
Tera Expert

After modifying my code to below:

function onSubmit() {
//Type appropriate comment here, and begin script below
//Get the field
var ap=g_form.getValue("approval");
if (ap=='approved')
{
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_req_item");
gr.query();
if (gr.next())
{
alert("Please attach the Required Document to proceed with submitting.");
return false;
}

 

I am getting this pop-up when i submit the record without attachment. But after attaching the attachment i am not able to submit the record.

 

GayathreeSeeth_0-1681042885135.png

 

Johns Marokky
Tera Guru

Hi @Gayathree Seeth ,

You need to modify the code little bit. Give me sometime I will prepare the script and give it to you.

You need to use the Script include and Client script for this.

 

Regards,

Johns