script include to set relevant default values based on field and conditions?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 03:57 AM
Hi Experts,
I'd like to create a script include to return the relevant default value for each field calling the script include and based on conditions of the current record ...
Example (just to understand the logic - this is not what is to be achieved ;-)):
IF incident contact_type is phone I wand to return Sys_ID of Group A as a default for assinment group, in case of email it might be Group B.
So I'd like to add in the default_value for assignment group something like javascript: thisFunktion().getDefault(assingement_group);
The script include then should look somehow like this ... to be used
...
getDefault: function(fieldname) {
if (fieldname == 'assignemt_groupl') {
var type = current.contact_type
var isEmail = type == 'email';
var isPhone = type == 'phone';
if (isEMail) { return 'Group A Sys ID'; }
else if (isPhone) { return 'Group B Sys ID'; }
}
}
else if (fieldname == 'what_ever_fieldl') {
...
}
I have tried this somewhile ago, but somehow it did not work so I'd like to ask for some advise before I start loosing again time doing something stupid.
Sure I could also to a client script calling a script include somehow, but as this is only relevant while initially loading the new record, this does not to be so clever I assume. Anyhow would prefer going this way ...
Any hints on this?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 04:20 AM
getDefault: function(fieldname) {
if (fieldname == 'assignemt_groupl') {
var type = current.contact_type // check value of contact_type choice value.
if(type == 'email')
{
var isEmail = true
}
if(type == 'phone');
{
var isPhone = true.
}
if (isEMail)
{
return 'Group A Sys ID';
}
else if (isPhone) { return 'Group B Sys ID'; }
}
}
else if (fieldname == 'what_ever_fieldl') {
...
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 04:23 AM
So my way of doing it is ok?
Thank you!
Will check soon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 04:56 AM
yes
write your code to run. if you have any problem in script let me know.
Thank You

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 07:32 AM
Somehow not working properly.
Returns [object Object] ?!!?
I call it via: javascript: new getDefault('u_field')
My Script include without class ...
function getSPMDefaultValue(current,fieldname) {
gs.info("DEBUG - Start");
if (fieldname == 'u_field') {
var isTest = new CheckifTest().isA();
var defval ="";
if(isTest) {
defVal = gs.getProperty('u_xxx_default1').toString();
return defVal;
}
gs.info("DEBUG -END");
}