Need to create log
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2024 02:06 AM
var jsonstr = '{"items":[{"sys_id":"8526043597943590335b76c11153af61","variables":{"requested_for_s_manager":"","cost_center":"","opened_by":"0c79dc3997122d10b3adfbbe2153af34","requested_for":"0c79dc3997122d10b3adfbbe2153af34","location":"0327dc7c979d7d10336ef52f2153afd5","department":"cd249968974a2950335b76c11153afda","new_hire_s_employee_id":"155004","depart":"cd249968974a2950335b76c11153afda","new_hire_s_manager":"0c79dc3997122d10b3adfbbe2153af34","company":"6b0ba8fe97ed2510335b76c11153af16","new_hire_last_name":"Abdi","new_hire_first_name":"Mohamud","new_hire_rehire":"Rehire","employee_type":"","start_date":"09-04-2024","title":"Employee Ambassador"}},{"sys_id":"0cb5859e97ac3150335b76c11153af88","variables":{"requested_for_s_manager":"d62380c39735a150335b76c11153af0a","cost_center":"5cd31d28974a2950335b76c11153af24","opened_by":"0c79dc3997122d10b3adfbbe2153af34","requested_for":"0c79dc3997122d10b3adfbbe2153af34","location":"","department_text":"AGR HR","department":"","employee_type":"1","as400":"false","printers_to_map":"","new_hire_employee_id":"155004","new_hire_rehire":"Rehire","ashleydirect":"false","new_hire_last_name":"Abdi","other_applications":"false","homestore_access":"false","additional_applications":"","ashleynet":"false","new_hire_location":"8327dc7c979d7d10336ef52f2153afd4","start_date":"09-04-2024","company":"Ashley Global Retail LLC","new_hire_first_name":"Mohamud","new_hire_s_manager":"0c79dc3997122d10b3adfbbe2153af34","title":"Employee Ambassador","user_to_copy_security_access_from":"","security_groups_needed":"","onbase":"false","please_list_applications":"","which_retail_markets":"","hardware_bundle":"Standard Laptop","network_drives":"false","reason_for_request":"Rehire"}},{"sys_id":"c721d4f59794f590b3adfbbe2153aff9","variables":{"requested_for_s_manager":"0c79dc3997122d10b3adfbbe2153af34","cost_center":"5cd31d28974a2950335b76c11153af24","opened_by":"0c79dc3997122d10b3adfbbe2153af34","requested_for":"7c96ed7b87949a10b1017558dabb357f","department":"cd249968974a2950335b76c11153afda","location":"8327dc7c979d7d10336ef52f2153afd4","reason_for_request":"Rehire"}},{"sys_id":"8c07d4f99794f590b3adfbbe2153aff1","variables":{"requested_for_s_manager":"0c79dc3997122d10b3adfbbe2153af34","cost_center":"5cd31d28974a2950335b76c11153af24","opened_by":"0c79dc3997122d10b3adfbbe2153af34","requested_for":"7c96ed7b87949a10b1017558dabb357f","department":"cd249968974a2950335b76c11153afda","location":"8327dc7c979d7d10336ef52f2153afd4","phone_type":"soft phone","reason_for_request":"Rehire"}},{"sys_id":"517d82c29762e110b3adfbbe2153af5e","variables":{"requested_for_s_manager":"0c79dc3997122d10b3adfbbe2153af34","cost_center":"5cd31d28974a2950335b76c11153af24","opened_by":"0c79dc3997122d10b3adfbbe2153af34","requested_for":"7c96ed7b87949a10b1017558dabb357f","department":"cd249968974a2950335b76c11153afda","location":"8327dc7c979d7d10336ef52f2153afd4","troubleshooting":"","computer":"Standard Laptop","laptop_bag":"Targus Premier Notebook Case","monitor":"Two 24\\" Monitors","laptop_dock":"Standard Dock","keyboard_mouse":"Wired Keyboard / Mouse bundle","headset":"Double Ear Headset","start_date":"09-04-2024","please_list_incidents_logged_for_device_issues":"","replacement_new_employee":"New User","reason_for_request":"Rehire"}}]}';
var catalogItemFields = [{
"sys_id": "8526043597943590335b76c11153af61",
"variables": ['requested_for', 'requested_for_s_manager', 'cost_center', 'location', 'department', 'new_hire_last_name', 'new_hire_first_name', 'title', 'company', 'start_date', 'new_hire_rehire', 'new_hire_s_manager', 'new_hire_s_employee_id']
},
{
"sys_id": '0cb5859e97ac3150335b76c11153af88',
"variables": ['requested_for', 'requested_for_s_manager', 'cost_center', 'location', 'department', 'new_hire_last_name', 'new_hire_first_name', 'reason_for_request', 'new_hire_location', 'new_hire_s_manager', 'title', 'start_date', 'new_hire_rehire']
},
{
"sys_id": 'c721d4f59794f590b3adfbbe2153aff9',
"variables": ['requested_for', 'requested_for_s_manager', 'cost_center', 'location', 'department', 'new_hire_last_name', 'new_hire_first_name', 'reason_for_request', 'new_hire_location', 'new_hire_s_manager', 'title', 'start_date', 'new_hire_rehire']
},
{
"sys_id": '8c07d4f99794f590b3adfbbe2153aff1',
"variables": ['requested_for', 'requested_for_s_manager', 'cost_center', 'location', 'department', 'new_hire_last_name', 'new_hire_first_name', 'reason_for_request', 'new_hire_location', 'new_hire_s_manager', 'title', 'start_date', 'new_hire_rehire']
},
{
"sys_id": '517d82c29762e110b3adfbbe2153af5e',
"variables": ['requested_for', 'requested_for_s_manager', 'cost_center', 'location', 'department', 'new_hire_last_name', 'new_hire_first_name', 'reason_for_request', 'new_hire_location', 'new_hire_s_manager', 'title', 'start_date', 'new_hire_rehire']
}
];
var jsonobj = JSON.parse(jsonstr);
for (var i = 0; i < jsonobj.items.length; i++) {
var item = jsonobj.items[i];
var catalogFields = catalogItemFields.find(field => field.sys_id === item.sys_id);
if (catalogFields) {
var missingFields = catalogFields.variables.filter(variable => {
return !item.variables[variable] || item.variables[variable].trim() === '';
});
if (missingFields.length > 0) {
var gr=new GlideRecord('sc_cat_item');
gr.get(item.sys_id);
gs.print('sys_id: ' + gr.name + ' - Mandatory data is missing: ' + missingFields.join(', '));
}
}
}
Scenario:->The catalog item we have variables and variable set for that which are the fields are mandatory need to populated in the flow designer log->For this script i have to add the variables are manually but i need to change it as dynamically(
"sys_id": "8526043597943590335b76c11153af61",
"variables": ['requested_for', 'requested_for_s_manager', 'cost_center', 'location', 'department', 'new_hire_last_name', 'new_hire_first_name', 'title', 'company', 'start_date', 'new_hire_rehire', 'new_hire_s_manager', 'new_hire_s_employee_id']
)
Labels:
- Labels:
-
Service Catalog
0 REPLIES 0