The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Declarative Action opening a new record but field is readOnly

davilu
Mega Sage

Hi Experts, our team has a Related List declarative action that opens a new record with some column values auto-populated.  Not sure if this is the correct way to do this, but found some community posts showing this particular method:

 

function onClick() {
	g_aw.openRecord('sn_hr_core_corrective_action_noa_cases', -1, {
		"query": "u_helpdesk_case=" + g_form.getUniqueValue() + "^u_noa_code=" + g_form.getValue('u_noa_code') + "^u_effective_date=" + g_form.getValue('u_effective_date')
	});
}

 

When logged in as an admin, the form appears as expected.  The NOA Code and Effective Date columns are configured to be Read Only:

davilu_0-1758664281960.png

 

But when impersonating an end user, the entire form is Read Only:

davilu_1-1758664339441.png

There are no client scripts, UI policies, ACL's that are causing this.  The only thing we can think of is this declarative action, but unsure why this would be happening.  Any suggestions?

3 REPLIES 3

tejas1111
Tera Contributor

What’s happening here is that g_aw.openRecord() with a query string doesn’t actually “pre-populate” the fields — instead, it loads the form in query mode with default values. When you’re admin, the read-only dictionary attributes are bypassed, so you still see the values filled. But for non-admin users, those fields are locked as per ACL/dictionary, so they stay read-only and the values don’t display until saved.

The right way to pre-populate fields in a new record from a Related List Declarative Action is:

Use the Default Values property in the Declarative Action instead of query string. That way the values are injected at record creation, not by query mode.

Or create an onClick client script/UI action that uses g_aw.createRecord() (not openRecord), which allows you to pass field:value pairs directly as defaults. Example:

function onClick() {
g_aw.createRecord('sn_hr_core_corrective_action_noa_cases', {
u_helpdesk_case: g_form.getUniqueValue(),
u_noa_code: g_form.getValue('u_noa_code'),
u_effective_date: g_form.getValue('u_effective_date')
});
}

 

thanks for the suggestion!  I gave that a try but the button doesn't do anything and I can't find any documentation on createRecord.  In my console I actually see a TypeError: g_aw.createRecord is not a function.

kaushal_snow
Mega Sage

Hi @davilu ,

 

Because the g_aw.openRecord method (GlideAgentWorkspace API) is being invoked without properly specifying parameters (like readOnlyForm: false), Workspace may default to rendering the newly opened record in read only mode (especially if the user lacks create/write permission), so you should pass the correct params object when calling g_aw.openRecord to prefill fields but allow edit.....and double check that no ACLs, UI policies, or workspace view settings inadvertently force full form read only behavior....

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/