Servicenow integration with Lumen

Seema12
Tera Contributor

whenever attachment added to incident sent it to lumen. Below is API format.

curl --location 'https://api.centurylink.com/ServiceAssurance/v1/Trouble/ticket/26322359/

--header 'Accept: application/json' \

--header 'Content-Type: application/json' \

--header 'Authorization: Bearer …\

--form 'File=@"/C:/Desktop/test.txt"' \

--form 'description="description"' \

--form 'encoding="base64"' \

--form 'uploaderPhone="999"' \

--form 'uploaderCountryCode="00"' \

--form 'uploaderName="Mary"'

--form 'uploaderEmail="mary@123.com"'

 

Not Able to get File location with '@' character in servicenow

 

3 REPLIES 3

The Machine
Kilo Sage

Perhaps try taking out the double quotes so it looks something like this.

'File=@ location of the file on file system'

Seema12
Tera Contributor

Hi,

I am trying with below code to achieve above requirement but getting error as invalid data, if anyone done it before cold you please suggest me with changes to get file location.

 

(function executeRule(current, previous /*null when async*/ ) {
    // Add your code here
    try {
        var sc_lumen = new lumen_methods();
        var token = sc_lumen.access_token_lumen();
        gs.log("Test token number to Attachment" + token);
        var test = "";
        var file = current.file_name;
        var u_mail = "";
        var u_contact = "";
        var u_name = "";
        var max_size = 2000000;
        var incObj = new GlideRecord('incident');
        var userRec = new GlideRecord('sys_user');
        var updated_user = gs.getUserID();
        gs.info("Test user " + updated_user);
        userRec.addQuery('sys_id', updated_user);
        userRec.query();
        if (userRec.next()) {
            u_mail = userRec.getValue("email");
            u_contact = userRec.getValue("phone");
            u_name = userRec.getValue("name");
        }
        var r = new sn_ws.RESTMessageV2('Test', 'Attachment');
        r.setRequestHeader("Content-Type", "application/json");
        r.setRequestHeader("Accept", "application/json");
        r.setRequestHeader("Authorization", "Bearer " + token.toString());
        r.setLogLevel('all');
        incObj.addQuery('sys_id', current.table_sys_id); //Queries only the attachments that are on the incident table
        incObj.addQuery('assignment_group.name', 'Test_group_name');
        incObj.orderByDesc('sys_created_on');
        incObj.setLimit(1);
        incObj.query()
        if (incObj.next()) {
            gs.log("Hello");
            var sa = new GlideSysAttachment();
            var binData = sa.getBytes(current);
            var size = parseInt(current.size_bytes);
            if (size > max_size) {
                gs.log('Ignoring sending of attachment due to size exceeds 2MB');
                current.setAbortAction(true);
            } else {
                var encData = GlideStringUtil.base64Encode(binData);
                file = current.file_name;
                test = incObj.getDisplayValue("correlation_id");
                r.setStringParameter('ticket', test);
                gs.log('sending of attachment: ' + file + " " + test);
                var note = incObj.comments.getJournalEntry(1).match(/\n.*/gm).join('').replace(/(\r\n|\n|\r)/gm, "").replace(/ {1,}/g, " ");
                gs.log("Print User details to Attachment: " + "Updated user: " + updated_user + " " + "Updated user sys id: " + u_mail + " " + u_contact + " " + u_name + " " + file + " " + note);
              file = "C:/Users/test/Downloads/laptop-from-above.jpg";
                  var raw = {
                    'File': file,
                    "description": "description",
                    "encoding": "base64",
                    "uploaderPhone": "(123) 456-7890",
                    "uploaderCountryCode": "00",
                    "uploaderName": "Test",
                    "uploaderEmail": "test@test.com"
                };
                gs.log('Testing Attachment body ' + raw);
                gs.log("Testing file name of Lumen" + file);
                r.setRequestBody(JSON.stringify(raw));         
                var response = r.execute();
                var responseBody = response.getBody();
                var httpStatus = response.getStatusCode();
                var objResp = JSON.parse(response.getBody());
                gs.log("HttpStatus to Attachment: " + httpStatus + " " + responseBody + " " + response + " " + objResp);
            }
        }
    } catch (ex) {
        var message = ex.message;
    }
})(current, previous);
 

Sorry @Seema12 

 

I am not a dev, so tough for me to check the code.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************