- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2019 07:09 PM
Hi Everyone,
Badly needed your help. I have this requirement where I need to make the customize field I create "u_actual_cashflow"
to become read-only in the expense line if the parent expense line has a child expense line.
I have this script constructed, but when it didn't work, I found out that GlideRecord should not be used in client script.
function onLoad(){
var rec = new GlideRecord('fm_expense_line');
var syst = g_form.getValue('number');
rec.addQuery(syst, 'parent');
rec.query();
if (rec.next()){
g_form.setReadOnly('u_actual_cashflow', true);
}
else {
g_form.setReadOnly('u_actual_cashflow', false);
}
}
Hope you can help me, Thanks in Advance
Solved! Go to Solution.
- Labels:
-
Cost Management
-
Financial Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2019 08:13 PM
You should use a Display Business Rule which runs the glide record and stores the value in the scratchpad. Then you can use the same scratchpad value in your client script to determine whether the field should be hidden or not
Community Question related to this.
Business Rule:
Name: Custom - Is Parent
Table: fm_expense_line
When: display
Script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('fm_expense_line');
gr.addQuery('parent',current.getUniqueValue());
gr.query();
if(gr.hasNext())
g_scratchpad.isParent = true;
else
g_scratchpad.isParent = false;
})(current, previous);
Client Script:
Name: Custom - Set Read Only
Type: onLoad
Table: Expense Line
Script:
function onLoad(){
if (g_scratchpad.isParent)
g_form.setReadOnly('u_actual_cashflow', true);
else
g_form.setReadOnly('u_actual_cashflow', false);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2019 07:20 PM
GlideRecord really should not be used in a Client Script and you should look into using GlideAjax for this as it's more efficient.
You can find info on GlideAjax here.
As a note though, your code has an error at this line, due to your arguments being in the wrong order.
rec.addQuery(syst, 'parent');
Should be
rec.addQuery("parent", syst);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2019 08:13 PM
You should use a Display Business Rule which runs the glide record and stores the value in the scratchpad. Then you can use the same scratchpad value in your client script to determine whether the field should be hidden or not
Community Question related to this.
Business Rule:
Name: Custom - Is Parent
Table: fm_expense_line
When: display
Script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('fm_expense_line');
gr.addQuery('parent',current.getUniqueValue());
gr.query();
if(gr.hasNext())
g_scratchpad.isParent = true;
else
g_scratchpad.isParent = false;
})(current, previous);
Client Script:
Name: Custom - Set Read Only
Type: onLoad
Table: Expense Line
Script:
function onLoad(){
if (g_scratchpad.isParent)
g_form.setReadOnly('u_actual_cashflow', true);
else
g_form.setReadOnly('u_actual_cashflow', false);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2021 03:14 AM
Hi
I have a akin requirement but the twist here is.
If the phase field on project is "initiating" then planned start and end date on project task should be editable however if project phase is "executing" or "closing" then planned start and end date on project task should be read only.
Can you help me on this?