- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 09:41 AM
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!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 10:40 AM - edited 04-10-2023 12:04 PM
Hi @Gayathree Seeth,
So as stated earlier for this you need to have client script as well as script include.
Client Script :
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 04:26 AM - edited 04-13-2023 04:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 09:54 AM
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.
Hope this is helpful.
Mark helpful if it helps in Solving your query.
Regards.
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2023 01:32 AM
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2023 05:24 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 09:23 AM
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