Want to save update set xml exported as an attachment

rahulyamgar
Tera Guru

Hello friends,

I have been using the "Export to XML" UI action on update set and now for some experimentational purpose I would like to save the XML to any of the ServiceNow record as an attachment. I had a look at the UI action "Export to XML" and found that there is a redirectURL. I tried to mimic the same using the REST GET Method and saving the output as an attachment to any of the record. But getting an 401 Unauthorized Error.

 
var current=new GlideRecord("sys_update_set");
current.get("f35cf0c507130110e835ff808c1ed07b");
var updateSetExport = new UpdateSetExport();

        var sysid = updateSetExport.exportUpdateSet(current);
		var url= "https://devxxx.service-now.com/export_update_set.do?sysparm_sys_id="+sysid+"&sysparm_delete_when_done=true&sysparm_ck=31ceffc107301110e835ff808c1ed0c566ce23842b976f8790d7ebde2f04d824dcdf0afe"
        var request = new sn_ws.RESTMessageV2();
        request.setEndpoint(url);
        request.setHttpMethod('GET');
        var user = gs.getProperty("CommitUser");
        var password = gs.getProperty("CommitUserPassword");
        request.setBasicAuth(user, password);
        request.setRequestHeader("Accept", "application/json");
        var updatesetid = request.saveResponseBodyAsAttachment(current.getTableName(), current.sys_id, current.getValue('name') + ".xml");
        var response = request.execute();
        var httpStatus = response.getStatusCode();
		
Above is returning 401 status code. Tried same in Postman but no help.
 
Could you please guide.
 
Thanks,
Rahul
8 REPLIES 8

Hello michaelward,
I'm currently facing the same issue since San Diego patch10-01-12-2023.

Is there an update to this problem?

I didnt not continue on this. I am sorry...

We have received the similar error when click on "Export to XML" on the new version. The solution was to replace the UI action script by passing the "&sysparm_is_remote=false&sysparm_ck=" + gs.getSessionToken()" parameters. That is by replacing the line

 

 

action.setRedirectURL("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true");

 

with

 

"action.setRedirectURL("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true&sysparm_is_remote=false&sysparm_ck=" + gs.getSessionToken());"

 

You can refer the UI Action from the latest release for the script inside "Export to XML" UI Action

 

Refer the below KB article for more information:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1116189

 

Mohammad Ziyad
Tera Contributor

We have received the similar error when click on "Export to XML" on the new version. The solution was to replace the UI action script by passing the "&sysparm_is_remote=false&sysparm_ck=" + gs.getSessionToken()" parameters. That is by replacing the line

 

 

action.setRedirectURL("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true");

 

with

 

"action.setRedirectURL("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true&sysparm_is_remote=false&sysparm_ck=" + gs.getSessionToken());"

 

You can refer the UI Action from the latest release for the script inside "Export to XML" UI Action

 

Refer the below KB article for more information:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1116189