Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Micro Focus Contributor
Micro Focus Contributor
824 views

Javascript help

Jump to solution

Dear Experts, 

 

I am a newbee in javascripting and hence need your help!

 

We have a requirement such that in device table (CIs), when we update the CI Owner (contact.name in device table) with the operator name (contact.name in operator table), there is an array field in the Operator table (owner.ci) which should update the CI Identifier (logical.name in device table). The functionality should be similar to operator and Assignment Group. Similar as when the Operator is updated with Assignment Group, the Assignment table is updated with Operator name and vice versa.

 

As of now, I have wriiten a code mentioned below. With this code I am able to Update the Operator record with the CI name, but if I change the Owner of the CI, the CI name still remains in the old Operator Record and in addition to that also appears under the new CI Owner.

 

var operator = new SCFile("operator")
var ciOwner = operator.owner_ci;
var operatorRecord = operator.doSelect("contact.name=\""+record.contact_name+"\"")
if(operatorRecord == RC_SUCCESS)
{
ciOwner.push(record.logical_name);
operator.doUpdate();
}

 

Thanks in advance.

 

Points will be awarded.

 

Regards,

Mithila

1 Solution

Accepted Solutions
Highlighted
Absent Member.. John Stagaman Absent Member..
Absent Member..

Re: Javascript help

Jump to solution

Why are you copying this information to the operator record?

 

If you just want to be able to see which CIs are assigned to a user, they can easily be displayed using a Virtual Join that shows all equipment assigned to the user (this can be added to the contacts form, operator form, or both easily). When opening a ticket the out of box filters already include any equipment assigned to the contact in the fill results for Affected CI. 

----------------------------------------------------
Kudos - what, where, how, and why
Want Good Answers? Ask Good Questions...
7 Replies
Acclaimed Contributor.. Vadim Gorda Acclaimed Contributor..
Acclaimed Contributor..

Re: Javascript help

Jump to solution

hello,

I guess you are doing that in triggers.

Add this script fragmnt there. I have not tested it though

 

if(record.contact_name!= oldrecord.contact_name){
    var foperator = new SCFile("operator")
    var foperatorRecord = foperator.doSelect("contact.name=\""+oldrecord.contact_name+"\"")
    if(foperatorRecord == RC_SUCCESS)
    {
        var length=system.functions.lng(foperatorRecord.owner_ci);
        var fresults = new Array();
        var fIndex=0;
        for (var i=0;i<length;++i)
        {
        if (foperatorRecord.owner_ci[i] != null)
        {
        var dup = false;
        for(var k=0;k<fIndex;++k)
        {
        if(fresults[k] == foperatorRecord.owner_ci[i])
        {
        dup = true;
        break;
        }
        }
        if(!dup)
        {
        fresults[fIndex] = foperatorRecord.owner_ci[i];
        ++fIndex;
        }
        }
        }
        
        foperatorRecord.owner_ci=fresults;        
        foperatorRecord.doUpdate();
    }
}

 

Micro Focus Contributor
Micro Focus Contributor

Re: Javascript help

Jump to solution

Hi Vadim,

 

Thank you very much.

 

Yes. I am calling the javascript in the triggers. But once I entered the code mentioned above, the application went into a hang mode. Please help.

 

Regards,

Mithila

 

Highlighted
Absent Member.. John Stagaman Absent Member..
Absent Member..

Re: Javascript help

Jump to solution

Why are you copying this information to the operator record?

 

If you just want to be able to see which CIs are assigned to a user, they can easily be displayed using a Virtual Join that shows all equipment assigned to the user (this can be added to the contacts form, operator form, or both easily). When opening a ticket the out of box filters already include any equipment assigned to the contact in the fill results for Affected CI. 

----------------------------------------------------
Kudos - what, where, how, and why
Want Good Answers? Ask Good Questions...
Acclaimed Contributor.. Vadim Gorda Acclaimed Contributor..
Acclaimed Contributor..

Re: Javascript help

Jump to solution

Hello, It might have gone in a loop as i have written it without a system.

If you were writting the first one yourself , debug it using prints and try t catch it.

Micro Focus Contributor
Micro Focus Contributor

Re: Javascript help

Jump to solution

Hi John,

 

We have a requirement such that whenever a CI is mapped to a Contact, the list of CIs mapped to that user should be displayed in an array field in the Operator record. And when the contact is disassociated from the CI or the CI is mapped to another user, it should be updated in the Operator record array field accordingly.

 

Thanks.

 

Regards,

Mithila S

0 Likes
Absent Member.. John Stagaman Absent Member..
Absent Member..

Re: Javascript help

Jump to solution

You can accomplish that without copying the data to the operator record (you can use a virtual join). If the only requirement is to display the user's associated devices on their operator record, there is no need to copy them. 

----------------------------------------------------
Kudos - what, where, how, and why
Want Good Answers? Ask Good Questions...
0 Likes
Micro Focus Contributor
Micro Focus Contributor

Re: Javascript help

Jump to solution

Thank you John!! :) It worked!!

 

Regards,

Mithila S

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.