Hi Everyone,
Is there any way that I can use
Substring
Substr
or
startsWith or any function like this in Custom Script.
Hey @ruchin78
In Setup > Custom Scripts, you can use any kind of javascript.
Use javascript string’s substr or slice methods:
-Anand.
I have already used it, before posting my query on the forum see my code below:
cur_frm.cscript.custom_refresh = function(doc) {
if(doc.item_code.substr(1,3)) {
cur_frm.set_df_property("revision", "hidden",false);
}
else
{ cur_frm.set_df_property("revision_no", "hidden",false);
}
}
See the error below:
Uncaught TypeError: Cannot read property ‘substr’ of undefined
Sorry, a typo in the script but I hope it will not impact the functionality of substring or substr
the correct code is:
cur_frm.cscript.custom_refresh = function(doc) {
if(doc.item_code.slice(1,3)) {
cur_frm.set_df_property("revision", "hidden",false);
}
else
{ cur_frm.set_df_property("revision_no", "hidden",true);
}
}
if(doc.item_code.substr(1,3)==“720”) {
cur_frm.set_df_property(“revision”, “hidden”,false);
}
else
{ cur_frm.set_df_property(“revision_no”, “hidden”,false);
}
and
if(doc.item_code.slice(1,3)==“720”) {
cur_frm.set_df_property(“revision”, “hidden”,false);
}
else
{ cur_frm.set_df_property(“revision_no”, “hidden”,false);
}
and
if(doc.item_code.substring(1,3)==“720”) {
cur_frm.set_df_property(“revision”, “hidden”,false);
}
else
{ cur_frm.set_df_property(“revision_no”, “hidden”,false);
}
all has same error
Can you explain your use case?
To get first three character, use doc.item_code.substr(0,3)
This is working fine.
To hide any field:
cur_frm.set_df_property("revision", "hidden",true);