Skip to content

Commit 989ff10

Browse files
authored
Merge branch 'main' into feature/user-profile-field-validation
2 parents 6154173 + 7cf9aaf commit 989ff10

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Fix script to remove leading and trailing spaces from a field in bulk
2+
3+
- we often encounter in a situation that a field has leading or trailing spaces and we want to remove it
4+
- This fix script helps to remove leading and trailing spaces from a field in bulk number.
5+
- Just for an example I have taken incident table and short description as a field.
6+
- feel free to modify and use it as per your requirement.
7+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var page = 1;
2+
var count = 0;
3+
var infoMsg = 'Fix Script to remove leading or trailing spaces from short_description. \n';
4+
var sd = ''; //sd inshort for shortdescription
5+
6+
7+
var regExSpacecheck = /^\s+|\s+$/g; //regular expression to check if a sentence has leading and trailing spaces.
8+
9+
var grInc = new GlideRecord('incident');
10+
grInc.addEncodedQuery('short_descriptionISNOTEMPTY');
11+
grInc.query();
12+
while (grInc.next()) {
13+
14+
if (regExSpacecheck.test(grInc.short_description)) {
15+
16+
infoMsg += 'incident record found with leading or trailing space for short_description: ' + grInc.sys_id + '\n';
17+
infoMsg += 'Sd ' + grInc.short_description + 'Contains leading or trailing spaces \n';
18+
sd = grInc.short_description;
19+
sd = sd.trim(); //trimmed value of short description
20+
infoMsg += 'sd is ' + sd + '\n';
21+
22+
if (regExSpacecheck.test(sd)) {
23+
infoMsg += 'sd: ' + sd + ' still has a trailing space\n';
24+
} else {
25+
infoMsg += 'sd: ' + sd + ' no longer contains trailing space \n';
26+
}
27+
//Replace the value for u_location_svid with the trimmed version
28+
grInc.setValue('short_description', sd);
29+
grInc.setWorkflow(false);
30+
grInc.update();
31+
32+
count++;
33+
34+
if (count == 50) {
35+
gs.info(infoMsg);
36+
page++;
37+
count = 0;
38+
infoMsg = 'Fix Script to remove leading or trailing spaces from short_description (' + page + ')\n';
39+
}
40+
41+
}
42+
43+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var html = '<div id="someid"><span>Hello World</span></div>'; // insert your html content
2+
var outputString = html.replace(/<\/?[^>]+(>|$)/g, ""); // output will a string without the HTML tags
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Will accept a html and remove all the html tags and give a string from it.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
UI Action
3+
Client - true
4+
action name - open_item
5+
show update - true ( As per your requirement)
6+
onClick - openItem();
7+
Workspace Form button - true
8+
Format for Configurable Workspace - true
9+
*/
10+
11+
//Workspace client script:
12+
function onClick() {
13+
var result = g_form.submit('open_item');
14+
if (!result) {
15+
return;
16+
}
17+
result.then(function() {
18+
var params = {};
19+
params.sysparm_parent_sys_id = g_form.getUniqueValue();
20+
params.sysparm_shortDescription = g_form.getValue('short_description');
21+
//add params as required, These params can be parsed and used in the record producer.
22+
g_service_catalog.openCatalogItem('sc_cat_item', 'recordproducer_sysid_here', params);
23+
//Use the record producer sys_id in second parameter.
24+
});
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Catalog Client script on the record producer/catalog item you want to open from ui action
3+
Name - ParseURL
4+
Type - Onload
5+
Applies on catalog item view - true
6+
*/
7+
8+
function onLoad() {
9+
10+
11+
g_form.setValue('task',parseURL('sysparm_parent_sys_id'));
12+
g_form.setValue('description',parseURL('sysparm_description));
13+
14+
function parseURL(paramName) {
15+
16+
var url = decodeURIComponent(top.location.href); //Get the URL and decode it
17+
var workspaceParams = url.split('extra-params/')[1]; //Split off the url on Extra params
18+
var allParams = workspaceParams.split('/'); //The params are split on slashes '/'
19+
20+
//Search for the parameter requested
21+
for (var i=0; i< allParams.length; i++) {
22+
if(allParams[i] == paramName) {
23+
return allParams[i+1];
24+
}
25+
}
26+
}
27+
}
28+
/*
29+
pass the parameter name which was used in the ui action to parse the value here.
30+
Example - parseURL('sysparm_description) as I am passing description value in the params from ui action.
31+
*/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
When we want to open a catalog item with details from current record and map it to the opened catalog form then we can use this code.
2+
3+
This UI Action and catalog client script Redirects you to the record producer or catalog item( based on the sys id provided) and auto-populates the fields from the parent record to the catalog item/record producer variables.
4+
5+
1. UI Action
6+
Client - true
7+
action name - open_item
8+
show update - true ( As per your requirement)
9+
onClick - openItem();
10+
Workspace Form button - true
11+
Format for Configurable Workspace - true
12+
13+
2. Catalog Client script.
14+
Type - Onload
15+
Applies on catalog item view - true
16+
Name - ParseURL
17+
18+
Note : Above UI Action works in Configurable workspace and opens the catalog item/record producer in workspace itself.

0 commit comments

Comments
 (0)