Re: Javascript help (183 Views)
Reply
Occasional Advisor
Mithila_S
Posts: 9
Registered: ‎02-03-2014
Message 1 of 8 (234 Views)
Accepted Solution

Javascript help

[ Edited ]

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

Please use plain text.
Honored Contributor
Vadim Gorda
Posts: 5,516
Registered: ‎11-10-2008
Message 2 of 8 (223 Views)

Re: Javascript help

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();
    }
}

 

Please use plain text.
Occasional Advisor
Mithila_S
Posts: 9
Registered: ‎02-03-2014
Message 3 of 8 (195 Views)

Re: Javascript help

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

 

Please use plain text.
Honored Contributor
John Stagaman
Posts: 3,152
Registered: ‎07-13-2007
Message 4 of 8 (183 Views)

Re: Javascript help

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...
Please use plain text.
Honored Contributor
Vadim Gorda
Posts: 5,516
Registered: ‎11-10-2008
Message 5 of 8 (169 Views)

Re: Javascript help

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.

Please use plain text.
Occasional Advisor
Mithila_S
Posts: 9
Registered: ‎02-03-2014
Message 6 of 8 (153 Views)

Re: Javascript help

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

Please use plain text.
Honored Contributor
John Stagaman
Posts: 3,152
Registered: ‎07-13-2007
Message 7 of 8 (150 Views)

Re: Javascript help

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...
Please use plain text.
Occasional Advisor
Mithila_S
Posts: 9
Registered: ‎02-03-2014
Message 8 of 8 (139 Views)

Re: Javascript help

Thank you John!! :) It worked!!

 

Regards,

Mithila S

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation