- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 08:38 AM
I have what appears to be a straight copy of the "New" button for Related Lists on a custom table.
It is setting a field on the custom table record (u_case). I need to see where that is happening because I need to set a different field depending on where the record is being created:
- Application PI - set the PI Case field on Communication
- Application CI - set the CI Case field on Communication
I'm not able to find any information on the "GlideappWizardIntercept".
In the logs, I can see that the "uri" variable contains elements that store the table name and sys_id of the record that my Comm record is related to.
How to I use these elements?
How / where do I see the field being set?
"New" UI Action:
var uri = action.getGlideURI();
var path = uri.getFileFromPath() + '';
path = path.substring(0, path.length - 5) + '.do';
uri.set('sys_id', '-1');
path = checkWizard(uri, path);
gs.info("New Communication - uri: " + uri);
gs.info("New Communication - path: " + path);
if (path)
action.setRedirectURL(uri.toString(path));
action.setNoPop(true);
function checkWizard(uri, path) {
var already = uri.get('WIZARD:action');
if (already == 'follow')
return null;
var wizID = new GlideappWizardIntercept(path).get();
if (!wizID)
return path;
uri.set('sysparm_parent', wizID);
uri.deleteParmameter('sysparm_referring_url');
uri.deleteMatchingParameter('sysparm_list_');
uri.deleteMatchingParameter('sysparm_record_');
uri.deleteParmameter('sys_is_list');
uri.deleteParmameter('sys_is_related_list');
uri.deleteParmameter('sys_submitted');
uri.deleteParmameter('sysparm_checked_items');
uri.deleteParmameter('sysparm_ref_list_query');
uri.deleteParmameter('sysparm_current_row');
uri.set('sysparm_referring_url', uri.toString());
uri.deleteMatchingParameter('fancy.');
uri.deleteMatchingParameter('sys_rownum');
uri.deleteMatchingParameter('sysparm_encoded');
uri.deleteMatchingParameter('sysparm_query_encoded');
uri.deleteParmameter('sysparm_refer');
return 'wizard_view.do';
}
TIA!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 10:58 AM
I wound up logging a HI ticket since I needed a fix for this issue. They've provided the following solution:
---
Hi Sue,
I was able to grab the information needed from the URL parameters on the new record and believe I have solution to the issue. You can create an onload client script on the u_communications table that will populate the CI Case field. To do so, please follow the steps outlined below.
1) Navigate to System Definition > Client Scripts
2) Click New to create a new script
3) Provide a name and fill in the other details as follows (see attachment script_fields.png for reference):
-Table: Communications [u_communications]
-UIType: Desktop
-Type: onload
4) In the Script section, enter the script shown below:
function onLoad() {
//Type appropriate comment here, and begin script below
// sample url param: sysparm_referring_url=x_enig_commcase_ci_case.do%3fsys_id%3d4fa8414c1bf3338007047592cd4bcb7a
var referringUrl = document.URL.parseQuery()['sysparm_referring_url'];
var isNewRecord = document.URL.indexOf('sys_id=-1') >= 0;
if(isNewRecord) {
var tableName = 'x_enig_commcase_ci_case';
var idIndex = referringUrl.indexOf('sys_id=');
// make sure we have the proper table name and a sys id
if( referringUrl.indexOf(tableName) >= 0 && idIndex > 0) {
// grab the record sys id
var startIndex = idIndex + 7; // sys_id= is 7 characters long
var endIndex = startIndex + 32; // sys id's are always 32 characters
var sysId = referringUrl.substring( startIndex, endIndex );
g_form.setValue('u_ci_case', sysId);
}
}
}
5) Submit the record
You should now see the CI Case field gets populated after clicking the New button on the All Communications related list. Please be aware that this is a custom script and is shown as an example. This script is not officially supported by ServiceNow and implementation is done at your own risk. The script provided looks for the sysparm_referring_url parameter in the url. It then ensures we're on a new record before continuing. If so, it will parse the sys_id of the referring record and use that to populate the CI Case field on the new record. Note that it is hard-coded to use the x_enig_commcase_ci_case table.
As I believe this will resolve the issue, I have moved this case to the solution proposed state. Please let me know if you have any additional questions regarding this case. Otherwise you may choose accept solution to bring the case to a close.
Thank You,
Ryan
---
I've implemented this client script and tested it. It works fine.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 12:14 PM
Any chance that field has a default value and it's not being set by this script? Guessing since I don't see it being set in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2019 11:54 AM
Unfortunately not.
I've checked business rules, client scripts, dictionary entries and there's nothing anywhere that sets the field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2019 03:52 PM
It should just be setting the reference field which connects it to the parent table, e.g., clicking new on a problem related list for incident table would automatically set the incident value to source incident record.
If that is not the case, other things working on that field (not the reference value field which connects the related list record), could be set either using display business rules, client scripts, or default value of those fields mentioned in dictionary.
Could you please confirm the type of field which is being set automatically?
Drop down fields show the first choice available if there is no "None" option specified in their choice list, it just shows the first option in the list when you load the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 10:58 AM
I wound up logging a HI ticket since I needed a fix for this issue. They've provided the following solution:
---
Hi Sue,
I was able to grab the information needed from the URL parameters on the new record and believe I have solution to the issue. You can create an onload client script on the u_communications table that will populate the CI Case field. To do so, please follow the steps outlined below.
1) Navigate to System Definition > Client Scripts
2) Click New to create a new script
3) Provide a name and fill in the other details as follows (see attachment script_fields.png for reference):
-Table: Communications [u_communications]
-UIType: Desktop
-Type: onload
4) In the Script section, enter the script shown below:
function onLoad() {
//Type appropriate comment here, and begin script below
// sample url param: sysparm_referring_url=x_enig_commcase_ci_case.do%3fsys_id%3d4fa8414c1bf3338007047592cd4bcb7a
var referringUrl = document.URL.parseQuery()['sysparm_referring_url'];
var isNewRecord = document.URL.indexOf('sys_id=-1') >= 0;
if(isNewRecord) {
var tableName = 'x_enig_commcase_ci_case';
var idIndex = referringUrl.indexOf('sys_id=');
// make sure we have the proper table name and a sys id
if( referringUrl.indexOf(tableName) >= 0 && idIndex > 0) {
// grab the record sys id
var startIndex = idIndex + 7; // sys_id= is 7 characters long
var endIndex = startIndex + 32; // sys id's are always 32 characters
var sysId = referringUrl.substring( startIndex, endIndex );
g_form.setValue('u_ci_case', sysId);
}
}
}
5) Submit the record
You should now see the CI Case field gets populated after clicking the New button on the All Communications related list. Please be aware that this is a custom script and is shown as an example. This script is not officially supported by ServiceNow and implementation is done at your own risk. The script provided looks for the sysparm_referring_url parameter in the url. It then ensures we're on a new record before continuing. If so, it will parse the sys_id of the referring record and use that to populate the CI Case field on the new record. Note that it is hard-coded to use the x_enig_commcase_ci_case table.
As I believe this will resolve the issue, I have moved this case to the solution proposed state. Please let me know if you have any additional questions regarding this case. Otherwise you may choose accept solution to bring the case to a close.
Thank You,
Ryan
---
I've implemented this client script and tested it. It works fine.