- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 05:25 AM
I have this script that sets values on INC/CHG/PROB forms if field is empty. By customer requirement I wish to change it so that it allways overwrite values in form, but only if field is not empty in the CI it gets value from.
To sum it up. CI gets selected on incident form, it checks if CI has value in Ass group, category and subcategory and if it does overwrite values on Incident form. How should i alter below script ?
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getReference('cmdb_ci', getci);
//Type appropriate comment here, and begin script below
}
function getci(ci){
if (g_form.getValue('category')== '' && ci.category !='')
{
g_form.setValue('category', ci.category);
}
if (g_form.getValue('subcategory')== '' && ci.subcategory !='')
{
g_form.setValue('subcategory', ci.subcategory);
}
if (g_form.getValue('assignment_group')== '' && ci.assignment_group !='')
{
g_form.setValue('assignment_group', ci.assignment_group);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 01:41 AM
You need to have if conditions to check whether category on ci is empty or not
Try the below script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getReference('cmdb_ci', getci);
//Type appropriate comment here, and begin script below
}
function getci(ci){
if (ci.category !='')
{
g_form.setValue('category', ci.category);
}
if (ci.subcategory !='')
{
g_form.setValue('subcategory', ci.subcategory);
}
if (ci.assignment_group !='')
g_form.setValue('assignment_group', ci.assignment_group); {
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 07:20 AM
You should be able to add something like:
if (newValue == '' || newValue == null) {
return;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 07:40 AM
Thanx. Could you show me how to put it in above script ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 08:48 AM
Actually, you already have the check if it's blank. Sorry didn't notice before. It's right here:
if (isLoading || newValue === '') {
return;
newValue === '' <-- checks if the newValue is blank, then do nothing (return)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 11:33 PM
But if i run the below script. And Assignment group, category and subcategory is filled out on the incident form and the CI' has empty fields on those 3, it still clears the field on the incident form to empty…
What is wrong ?
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getReference('cmdb_ci', getci);
//Type appropriate comment here, and begin script below
}
function getci(ci){
//if (g_form.getValue('category')== '' && ci.category !='')
{
g_form.setValue('category', ci.category);
}
{
g_form.setValue('subcategory', ci.subcategory);
g_form.setValue('assignment_group', ci.assignment_group); {
}