Wednesday, April 22, 2015

ServiceNow: Stop or restrict the record from saving when Reference icon is clicked

ServiceNow Reference icon


In ServiceNow, when user clicks on Reference icon, for e.g. on Asset related interface, just to see the referred record, for e.g. Configuration Item, it redirects the user to the interface of referred record. Having said this, if user again navigates back to the Asset interface, auto save for Asset record is triggered even though no field modification is done on either interface. This type of behavior is often seen for Reference icon click in ServiceNow. This creates unintended confusion of record being modified by user who just tried to view records (for e.g. Asset to Configuration Item record navigation).


In this scenario, there is no way to stop the update action once it is initiated on Reference icon click. We can’t call autoSysFields(false) for current record in any business rule and expect to stop the update of audit fields like Updated and Updated By. Because autoSysFields(false) is called before update action is initiated.

If the root cause of update action is known, then as a workaround, if possible, that logic can be tried to shift from client script to business rule in ServiceNow. For e.g. if u_view field is set in any client script for OnLoad event, every time it set the value of u_view field which in turn mark the current record to modified status. This initiate the update action when Reference icon is clicked for any referred record. It tries to first update the current Asset record and then navigates to interface of referred record. In this case, it looks like user has not modified any field and auto save has been triggered on Reference icon. To avoid the update action in this case, client script logic can be moved to a business rule.


For example below script can identify the view name in business rule (before update), if view name is needed internally for some business logic.

var transaction = GlideTransaction.get();
var viewName = transaction.getRequestParameter("sysparm_view");

Once view name is identified, it can be used for desired purpose and client script just to set value of  u_view field can be deactivated and tested. If no auto save trigger on Reference icon click, then it means the issue has been addressed. If not, then it means some other field also changes internally which in turn trigger update action. Sometime it is not known which field value changes internally. In that situation below script can be used in business rule (before update).

var actionName = action.getActionName();
gs.addInfoMessage('Action performed: ' + actionName);
if (actionName == 'sysverb_check_save'){
    if (typeof GlideScriptRecordUtil != 'undefined')
       var gru = GlideScriptRecordUtil.get(current);
    else
       var gru = Packages.com.glide.script.GlideRecordUtil.get(current);
    var changedFields = gru.getChangedFields();
    gs.addInfoMessage('Fields changed: ' + changedFields.toString());
}


Above code patch will provide the list of fields modified for which update action initiate on Reference icon click. For e.g. Some financial field like ‘Cost’ on Asset side, which stores value in currency is initialized at runtime. By default its value is blank. When form is loaded, its value is changed to ‘$0.00’ which marks the current record has been modified. In such scenario, those can be updated with default value as ‘$0.00’ for blank in existing records and at table level such field can be set to default value as ‘$0.00’ so that it is not blank at the time of record creation. Once this activity is addressed, try to test and see if Reference icon click trigger update action.

If it is not possible to move any field logic from client script to business rule, then it is not possible to avoid the record save on Reference icon click. As an alternate option, users can be notified that some fields on the interface has been modified by validating g_form.modified in onSubmit event for actionName == 'sysverb_check_save' and provide an appropriate message by returning false. That will cancel the update action on Reference icon click. But it will also stop the user from navigating to the interface of referred record.


Otherwise glide.ui.reference.readonly.clickthrough property value can be changed in UI properties, if business users have no issue to have the impact on all interfaces wherein Reference icon no longer appear.

Another workaround is to change glide.ui.clickthrough.popup property to open a new tab every time user click on Reference icon (instead of opening the referred record interface in same window). However this change will apply to all interfaces and Reference icon will also appear in different way.



Thursday, April 09, 2015

ServiceNow: Steps of Scheduled Email for an existing report not capturing in local updateset

ServiceNow Steps of Scheduled Email


In ServiceNow, when we create a Scheduled Email for an existing report, and look forward to capture related steps as part of an updateset, please be aware that Scheduled Email steps are not captured. This seems to be ServiceNow drawback or limitation. All steps related to the Scheduled Email of Report need to be separately captured in an independent file. Otherwise those steps need to be manually applied in destination ServiceNow environment. 

Scheduled Email record can be separately saved in XML format file and then same XML file can be imported back into the destination ServiceNow environment to implement the Scheduled Email for an existing report. 

So initially below steps should be followed to export and save Scheduled Email record as XML file
  • Open Scheduled Email of Report
  • Right click on list header Scheduled Email of Report and select Export à XML (This Record)
  • Save the XML Document in local folder of your machine
Once XML file is created, below steps should be followed to import the XML file which will apply all steps to implement Scheduled Email for ServiceNow report

To import the XML file as Scheduled Email record in destination environment, elevated privileges access is needed. Hence select the elevated privileges (lock) icon beside user name. In the ‘Activate an Elevated Privilege’ dialog box, select the ‘security_admin’ check box and click OK. Now proceed further to import XML file using below steps
  • Go to Reports à Scheduled Reports
  • In the destination environment, right click on list header on Scheduled Email of Reports page and select “Import XML”.
  • Browse and select the XML Document in local folder of your machine and click Upload.
Similar kind of situation arises in case of Scheduled Jobs in ServiceNow.

ServiceNow: Steps to create Scheduled Email of Report

ServiceNow Scheduled Email of Report


Basically creating a Scheduled Email of Report in ServiceNow means scheduling a notification email for your desired business users who will receive the report (as an attachment) . Please note that the report need to be already created and should exist in ServiceNow reports.

Scheduled Email of Report in ServiceNow can be created using below steps:
  1. Click on Scheduled Reports link besides Administration link on Reports à View / Run screen or click ‘Scheduled Reports’ link under Reports section
  2. Click on New button to create the schedule for the report
  3. Fill details on Scheduled Email of Report screen
  4. Name: Fill name of Scheduled Email of Report
  5. Report: Specify the report name to be scheduled
  6. Email addresses: Specify the email addresses which acts recipients for the email
  7. Set the schedule time for the report to run daily
  8. Enter the Subject for the email notification
  9. Enter body text for the scheduled email
  10. Set Type for e.g. as ‘Excel’
  11. Set Run as for e.g. ‘System Administrator’
  12. Click on Save to save the report.

ServiceNow: Steps to create a Global Report of List type

ServiceNow Global Report

ServiceNow Global Report


To create a Global Report of List type in ServiceNow, below steps need to be followed:

  • Enter ‘Report’ in Type Filter Text box on left hand side on top left
  • Click on Reports à View / Run. Clicking View/ Run will open Reports screen
  • Click on New button to create a global report
  • Populate values for following fields

Name: Name for the global report
Type: Select ‘List’
Table: Select Table Name. For e.g. Hardware (alm_hardware)
Group By: Leave it blank if group by is not needed
Export details: Keep it checked
Header Footer Template: Default
Visible To: Select ‘Me’ option if like to visible to yourself, else select ‘Groups and Users’ option if you like the report to be visible for an specific Groups or custom list of users. Else select ‘Everyone’ option, if you like to make the report visible to all
Filter and Order: This can be used to set filter for records in selected Table
Columns: Select desired column list from Available to Selected box. To selected field to more granular level for fields appearing in green with plus sign, select the field and click sign icon. This will expand the field list. Normally this behaviour is seen for fields which act as Reference field. Now you can select the desired field name.

Once all values are selected, click Run Report which in turn will run the report and show the output records below in grid. You can click Save button to save the report.