retrieve a line from description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 05:21 AM
Hello
I am working on getting a line extraxted from description field on a changed and detials looks someting like this mentioned below
What i am looking fir is retrieve line which says Provision Type : Standard
Requested For : Test user
Requested By : Test user
Requested For's Manager : Jyoti Das
Best Method of Contact : test
IsCGP : true
Requested By Date : 2023-09-13 07:58:34
Configuration Item : CI name
Application contact : Approval User1
Location : ABC
Nautical : Shore
Daptiv Workspace / Project Name : s
Car No : s
OS Type : Windows
Provision Type : Standard
Environment Type : Production
Short Description : test
Business Reason for Request : stes
Additional Comments : test
tried using
var gr = new GlideRecord('change_request');
gr.get('b6f50cb69749f1509a4216a00153af03');
var abc = gr.description;
var rajesh = abc.split('\n');
but both fails stating invalid object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 05:27 AM
Hi,
Please try below code.
var gr = new GlideRecord('change_request');
if (gr.get('sys_id', 'your_change_request_sys_id')) {
var description = gr.description.toString();
// Now, you can work with the description field
var lines = description.split('\n');
for (var i = 0; i < lines.length; i++) {
if (lines[i].indexOf('Provision Type : Standard') !== -1) {
gs.info('Found line: ' + lines[i]);
break; // Exit the loop once found
}
}
} else {
gs.error('Change request not found');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 06:14 AM
Missed to inform this is in the Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 12:50 PM
Hi,
Please try below code run script activity
var gr = new GlideRecord('change_request');
if (gr.get('29d6e06447017154267b9763636d4393')) { // Replace with the correct change request ID
var description = gr.getValue('description');
var lines = description.split('\n');
for (var i = 0; i < lines.length; i++) {
if (lines[i].indexOf('Provision Type : Standard') !== -1) {
var provisionTypeLine = lines[i];
break; // Exit the loop once the line is found
}
}
if (provisionTypeLine) {
// You've found the line, and it's stored in provisionTypeLine
gs.info("Provision Type Line: " + provisionTypeLine);
} else {
gs.info("Provision Type Line not found");
}
} else {
gs.info("Change request not found");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 05:37 AM
Hi,
Try something like this, just change the config to fit your needs:
var incGR = new GlideRecord('incident');
if(incGR.get('3609a3b08719351025c58409cebb3543'){
var desc = incGR.getValue('description');
var arrayDesciption = desc.split('\n');
for (var i=0; i<arrayDesciption.length; i++){
//gs.info('Desc line: ' + arrayDesciption[i]);
if(arrayDesciption[i].indexOf('Provision Type :') > -1){
gs.info('Found it: ' + arrayDesciption[i])
}
}
}