Give write access to a particular field in the form

Bijay Kumar Sha
Giga Guru

Hi,

I've requirement to give 'write' access to the user having a particular role to 'Risk Score' field available in "sn_vul_vulnerable_item" table. Please see the screenshot as below (by default this field is read-only):

BijayKumarSha_0-1674568214760.png

 

I've created a role called "sn_vul.vit.riskscore" and an ACL called "sn_vul_vulnerable_item.risk_score" for this. Please see the screenshot as below:

BijayKumarSha_1-1674568352115.pngBijayKumarSha_2-1674568407059.png

 

If I'm giving this particular role to the user, still user doesn't have access to edit 'Risk score' field. 

 

Let me know if I'm missing anything or any other action item needs to be taken care. 

 

6 REPLIES 6

shivangi k
Kilo Sage

Hi @Bijay Kumar Sha ,

 

You can do this with help of onLoad client script:

 

function onLoad() {
//Type appropriate comment here, and begin script below
if(g_user.hasRoles('sn_vul.vit.riskscore'));
{
g_form.setReadOnly('risk_score',false);
}
else
{
g_form.setReadOnly('risk_score',true);
}
}

 

Please mark helpful if it helped you.

 

Regards,

 

Hi @shivangi k  Thank you for the response. 

I've another condition into this role i.e if the "Source" field is 'Manual' then the user should have write access to Risk Score field. 

However, I've added this condition in the ACL itself as below screenshot:

BijayKumarSha_0-1674574690915.png

So, will the client script still works or do I need to do anything more?

shivangi k
Kilo Sage

Hi @Bijay Kumar Sha 

 

Either you will you use ACL or Client script in both you can add condition related to source filed and it will work.

For client script:

function onLoad() {
//Type appropriate comment here, and begin script below

var ga=g_form.getValue('source');
if(g_user.hasRoles('sn_vul.vit.riskscore')&& (ga==manual));
{
g_form.setReadOnly('risk_score',false);
}
else
{
g_form.setReadOnly('risk_score',true);
}
}

Regards,

 

Please mark helpful if it helped you.

Hi @shivangi k  this client script is not able to make ReadOnly False for the 'risk_score' field. 

Is this because by default in the dictionary entry 'risk_score' field is ReadOnly True... If this is the case then how to achieve this? It's mandatory to make ReadOnly to 'risk_score' field by default. But only if the user has 'sn_vul.vit.riskscore' role, then it should be editable.