How to copy attachment from sys_template to change when it is created from sys_template?

rohitservicenow
Mega Guru

Hi, 

I am trying to copy attachment to change request when a sys_template is applied?

 

Found couple of post where it is suggested to create a new filed on change request which refers to sys_template field, but wondering how to get this field auto populated when the sys_template is applied from toggle bar?

 

Please suggest best way to implement this solution? thank you

 

1 ACCEPTED SOLUTION

Thank you @Murthy Ch

Created an additional field on Change request table which will be used to copy the template name when the template is applied. Created a BR on sys_template table which will map the existing template to the new field on change request, so whenever the template is applied, the new field get's populated and I have reference to template from which I can copy the attachment to CR using the GlideSysAttachment.copy method. 

 

View solution in original post

3 REPLIES 3

Murthy Ch
Giga Sage

Hi @rohitservicenow 

I think finding an which template is applied is difficult. So there will be some fields will set via Template.

So use the unique value of the field which you are mapping.

Let's say in my case I'm copying the attachment when short description changes and when template is applied. (short description is unique here)

Field name Short Description in CS

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (isTemplate && g_form.getValue("short_description") == "Applying template") {  //when template applied and short description is unique
        var ajax = new GlideAjax('Newglidingabc');
        ajax.addParam('sysparm_name', 'copyAttachmentwhenTemp');
        ajax.addParam('sysparm_existing', g_form.getUniqueValue());
        ajax.getXML(getRITMdata);
    }

    function getRITMdata(response) {
        // do nothing...
    }

}
copyAttachmentwhenTemp: function() {
        GlideSysAttachment.copy("sys_template", "4b175dd20a0a0b99004f35e506563fc6", "change_request", this.getParameter("sysparm_existing"));
    },

//store the attachment in template record and call it here...

Hope it helps..

 

 

 

 

Thanks,
Murthy

Thank you @Murthy Ch

Created an additional field on Change request table which will be used to copy the template name when the template is applied. Created a BR on sys_template table which will map the existing template to the new field on change request, so whenever the template is applied, the new field get's populated and I have reference to template from which I can copy the attachment to CR using the GlideSysAttachment.copy method. 

 

Hi @rohitservicenow 

yes you can like that but it will require a new field creation. In my example it doesn't require to create a new field if any field value is unique:)

 

Thanks,
Murthy