- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
11-04-2024 05:29 AM - edited 11-04-2024 05:40 AM
Purpose
OOB Employee Form's condition builder restricted to a single record. "Make sure that the result is a match to a single record." ~ ServiceNow Docs
Existing OOB Employee Form field mapping limitations
- If multiple records are found, then mapping will fail.
- Condition builder cannot be used to build complex query.
- Value can be mapped only to a single record.
Features of Employee Form Field Mapping Utility
This Utility uses a custom action which will map the values to desired record/records overcome these limitations.
- Form values can be mapped to different records and tables.
- Complex query can be added for target record.
- Execution history is available as it runs via flow.
- Notifications/alerts can be generated on error.
- Utility is fully customizable according to need.
Demo
Procedure
- Download(from attachments) and install the update set.
- Create a flow on HR Task with following trigger conditions. Choose the Employee form in the Survey field.
- Add the lookup record/records (multiple update) action and update the table with the query.
- Add the utility action - Employee Form Field Mapping Utility
Target Table Name of the table where your data map. Target Record Record reference where the values update. Employee Form Employee form used in the HR Task Question Options of above selected Employee form’s question. Choose question followed by the backend name of the field of target record HR Task Reference of the current HR Task
- Submit and Publish the flow. You are good to go.
Code and Logic of Employee form mapping Action
Action Inputs
Action Script
Action Script Include
var EmployeeFormMappingUtil = Class.create();
EmployeeFormMappingUtil.prototype = {
initialize: function() {},
process: function(target_table, target_record, questions_mapping, assessment_instance) {
questions_mapping = questions_mapping.trim();
questions_mapping = questions_mapping.replace(/\ufeff/g, '');
var questions_mappings = questions_mapping.split('^');
var numRecords;
var message;
if (!gs.nil(target_record)) {
var recordGr = new GlideRecord(target_table);
if (recordGr.get(target_record.sys_id)) {
mapFields();
recordGr.update();
}
}
function mapFields() {
var tempInt;
for (var i = 0; i < questions_mappings.length; i++) {
var metric = questions_mappings[i].split("=")[0] + "";
var field = questions_mappings[i].split("=")[1] + "";
var qaGr = new GlideRecord('asmt_metric_result');
qaGr.addQuery('metric', metric);
qaGr.addQuery('instance', assessment_instance);
qaGr.query();
if (qaGr.next()) {
var glideElement = recordGr.getElement(field);
var typeString = glideElement.getED().getInternalType();
var datatype = qaGr.metric.datatype.toString();
if (typeString == 'reference') {
if (qaGr.reference_value)
recordGr.setValue(field, qaGr.reference_value);
} else if (typeString == "journal_input") {
recordGr[field] = qaGr.string_value.toString(); //setvalue doesnt support journal type field
} else {
// for 'string', 'date', and 'datetime' metric types, the value is stored as 0
if (['date', 'datetime'].indexOf(datatype) > -1 && !gs.nil(qaGr.string_value)) {
var gd = new GlideDate();
gd.setDisplayValue(qaGr.string_value.toString());
recordGr.setValue(field, gd);
//recordGr.setValue( field,qaGr.string_value);
} else if (['string'].indexOf(datatype) === -1 && !gs.nil(qaGr.string_value))
recordGr.setValue(field, qaGr.string_value);
else if (qaGr.string_value)
recordGr.setValue(field, qaGr.string_value);
else if (qaGr.reference_value) {
var gr_ref = new GlideRecord(qaGr.metric.reference_table);
if (gr_ref.get(qaGr.getValue('reference_value')))
recordGr.setValue(field, gr_ref.getDisplayValue(gr_ref.getDisplayName()));
else
recordGr.setValue(field, qaGr.reference_value);
}
}
}
}
}
},
type: 'EmployeeFormMappingUtil'
};
- 1,497 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Pranesh072 - Thanks for sharing this. This is awesome. My employee form question is multi choice and I want to map it to the list field on the table. This is working if one choice is made and the field is string field on the table.
Any suggestion?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Simran321 You can try this it will map the choice value to the string field without any issue.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Pranesh072 - I want to map this to list field not string
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Simran321 I dont think it is possible in current solution, to convert the string value to reference sys_id for list field. You can modify the utility for your use case.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I am trying to do this but my Employee Form doesn't list the forms. I have HR task with the Employee for but i need to update hr case.