- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 04:11 PM
Hello,
Is there a way to retain existing values of the field when using a transform map?
My requirement is for example I have this record on group table:
group name = cab approval
type = itil
Then I'm using transform map to update this record. The data I'm loading for example is:
group name = cab approval
type = catalog
What needs to happen after transform is:
group name = cab approval
type = itil, catalog
I need to retain the existing value of the type field on the group table after transform. If not empty then update, if empty then inser
Appreciate all the help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 06:48 AM
The code does not implement the part where it is supposed to check whether the current list already contains the item to be added. I would go with a field map script as below:
answer = (function transformEntry (source, target, action, log) {
var groupTypeUniqueValues = getGroupTypeUniqueValues('' + source.u_sys_user_group_type);
return addTypeToNewGroup(action, groupTypeUniqueValues) ||
addTypeToGroupWithNoType(target.type.nil(), groupTypeUniqueValues) ||
addTypeToGroupWithType(getGroupTypes('' + target.type), groupTypeUniqueValues);
function addMissingTypes () {
return function (existingValues, newValue) {
if (existingValues.indexOf(newValue) < 0)
existingValues.push(newValue);
return existingValues;
};
}
function addTypeToGroupWithNoType (typeIsEmpty, value) {
if (typeIsEmpty)
return value.join(',');
}
function addTypeToGroupWithType (existingValues, newValues) {
return newValues
.reduce(addMissingTypes(), existingValues)
.join(',');
}
function addTypeToNewGroup (action, value) {
if (action == 'insert')
return value.join(',');
}
function getGroupTypes (groupTypeList) {
return groupTypeList
.split(semiColonCommaOrNewLineSorrundedByWhiteSpace())
.filter(retainNotEmpty())
.filter(retainUnique());
}
function getGroupTypeUniqueValues (groupTypeList) {
return groupTypeList
.split(semiColonCommaOrNewLineSorrundedByWhiteSpace())
.filter(retainNotEmpty())
.map(getUniqueValueFromDisplayValue('sys_user_group_type'))
.filter(retainNotEmpty())
.filter(retainUnique());
}
function getUniqueValueFromDisplayValue (tableName) {
return function getUniqueValueFromDisplayValue (displayValue) {
return '' + GetIDValue(tableName, displayValue);
};
}
function retainNotEmpty () {
return function retainNotEmpty (item) {
return item != '';
};
}
function retainUnique () {
return function retainUnique (item, index, items) {
return items.indexOf(item) == index;
};
}
function semiColonCommaOrNewLineSorrundedByWhiteSpace () {
return /\s*[;,\n]\s*/g;
}
})(source, target, action, log);
answer;
Tested it with a field map setup in a transform map as below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 06:48 AM
The code does not implement the part where it is supposed to check whether the current list already contains the item to be added. I would go with a field map script as below:
answer = (function transformEntry (source, target, action, log) {
var groupTypeUniqueValues = getGroupTypeUniqueValues('' + source.u_sys_user_group_type);
return addTypeToNewGroup(action, groupTypeUniqueValues) ||
addTypeToGroupWithNoType(target.type.nil(), groupTypeUniqueValues) ||
addTypeToGroupWithType(getGroupTypes('' + target.type), groupTypeUniqueValues);
function addMissingTypes () {
return function (existingValues, newValue) {
if (existingValues.indexOf(newValue) < 0)
existingValues.push(newValue);
return existingValues;
};
}
function addTypeToGroupWithNoType (typeIsEmpty, value) {
if (typeIsEmpty)
return value.join(',');
}
function addTypeToGroupWithType (existingValues, newValues) {
return newValues
.reduce(addMissingTypes(), existingValues)
.join(',');
}
function addTypeToNewGroup (action, value) {
if (action == 'insert')
return value.join(',');
}
function getGroupTypes (groupTypeList) {
return groupTypeList
.split(semiColonCommaOrNewLineSorrundedByWhiteSpace())
.filter(retainNotEmpty())
.filter(retainUnique());
}
function getGroupTypeUniqueValues (groupTypeList) {
return groupTypeList
.split(semiColonCommaOrNewLineSorrundedByWhiteSpace())
.filter(retainNotEmpty())
.map(getUniqueValueFromDisplayValue('sys_user_group_type'))
.filter(retainNotEmpty())
.filter(retainUnique());
}
function getUniqueValueFromDisplayValue (tableName) {
return function getUniqueValueFromDisplayValue (displayValue) {
return '' + GetIDValue(tableName, displayValue);
};
}
function retainNotEmpty () {
return function retainNotEmpty (item) {
return item != '';
};
}
function retainUnique () {
return function retainUnique (item, index, items) {
return items.indexOf(item) == index;
};
}
function semiColonCommaOrNewLineSorrundedByWhiteSpace () {
return /\s*[;,\n]\s*/g;
}
})(source, target, action, log);
answer;
Tested it with a field map setup in a transform map as below: