its_SumitNow
Mega Sage

Hii @Rajyalakshmi,

I understood your use case. I actually got the same question in an interview.
To achieve this, you need to create a Record Producer with 3 variables:

  1. Table (Reference → sys_db_object)

  2. Description (String)

  3. Caller (Reference → sys_user)

Below is the script I used for mapping the variables dynamically.
You can apply the same logic:

// Ensure variable names match those defined in the Record Producer
var selectedTable = producer.select_table;
var caller = producer.caller;
var description = producer.short_description;

if (selectedTable == 'incident') {
var inc = new GlideRecord('incident');
inc.initialize();
inc.caller_id = caller;
inc.short_description = description;
inc.insert();
action.setRedirectURL(inc);
current.setAbortAction(true); // Prevent default record creation

} else if (selectedTable == 'problem') {
var prob = new GlideRecord('problem');
prob.initialize();
prob.caller_id = caller;
prob.short_description = description;
prob.insert();
current.setAbortAction(true); // Prevent default record creation
}

If this helps, please mark the answer as helpful in the ServiceNow Community