Re: How to populate source field in link record if query doesn't return records (403 Views)
Reply
Regular Advisor
Ulises Jorge Bido
Posts: 106
Registered: ‎10-19-2010
Message 1 of 5 (450 Views)
Accepted Solution

How to populate source field in link record if query doesn't return records

Dear folks,

 

I want to update the 'incidents' link record in a such a way that the value of the 'logical.name' field will be set to a  text string if the query for this field in the link record returns no record.  So in the link record, for 'logical.name' I have the following query:

 

 

if (not null(affected.item in $File) and affected.item in $File="My Devices" and not null(contact.name in $File)) then ($query="contact.name=contact.name in $File")

 

if the query is successfull, the value of 'logical.name' in the interaction is set to the value of 'logical.name' in the device table.  If the query is not successful (meaning, this particular user does not have an item with his/her name in the 'device' table, I get the following error message:

 

"Cannot find related information in device"

 

What I would like to happen instead is to automatically set the value of 'logical.name' in the interaction record to "No Device record for this user".

 

How do I do this?  I was able to add some code in the "Post Expression" field to set the value of another field to whatever text string I wanted in case that the query failed, but I can't do the same with the 'logical.name' field.  

 

I would appreciate your input with this matter.

 

Kind regards,

 

Ulises

 

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

Re: How to populate source field in link record if query doesn't return records

Hello,

Can you try this script portion on the Post JS for that link line?

 

var device = new SCFile("device");
if (vars.$File.affected_item!=null && vars.$File.affected_item=="My Devices" && vars.$File.contact_name!=null){
    var rc = device.doSelect("contact.name=\""+vars.$File.contact_name+"\"");
    if (rc != RC_SUCCESS) {
        vars.$File.logical_name="No Device record for this user";
    }    
}

Please use plain text.
Regular Advisor
Ulises Jorge Bido
Posts: 106
Registered: ‎10-19-2010
Message 3 of 5 (389 Views)

Re: How to populate source field in link record if query doesn't return records

Mr. Gorda,

 

Thanks a lot for your reply.  I tried your solution, but it did not work as I still got the error message ("Cannot find related information in device").  I performed a trace and it looks that once the query fails the RAD routine calls the error message and ignores the Post JS.  

 

You'll see the following on line 2771 of the enclosed trace file:

 

4972( 1916) 01/10/2014 11:02:42 RTE D DBQUERY^F^device(oracle10)^15^0.000000^ ^0^0.000000^"contact.name="HILVETV""^ ^0.000000^0.000000 ( [ 3] us.link select.records )
4972( 1916) 01/10/2014 11:02:42 RTE D (0x24D9CBE0) DBACCESS - Select against file device in 0.000000 seconds [rc=9 ]
4972( 1916) 01/10/2014 11:02:42 RTE D RADTRACE 0 [ 3] us.link no.related.action decision CPU( 0 2702 )
4972( 1916) 01/10/2014 11:02:42 RTE D RADTRACE 0 [ 3] us.link no.related.records process CPU( 0 2702 )
4972( 1916) 01/10/2014 11:02:42 RTE D (0x23FB6B40) DBACCESS - Cache Find against file scmessage found 0 records (syslanguage="en" and class="us" and message.id="67")

 

I'm enclosing the trace and the link record if you'd like to look closely into this.

 

Kind regards,

 

Ulises

Please use plain text.
Regular Advisor
Ulises Jorge Bido
Posts: 106
Registered: ‎10-19-2010
Message 4 of 5 (382 Views)

Re: How to populate source field in link record if query doesn't return records

Mr. Gorda,

I performed some minor modifications to your script and was able to make it work. Also, I had to put it in the 'Javascript' section, not the Post Javascript for it to work.

Here's my version:

var device = new SCFile("device");
if (vars.$File.affected_item!=null && vars.$File.affected_item=="My Devices" && vars.$File.callback_contact!=null){
var rc = device.doSelect("contact.name=\""+vars.$File.callback_contact+"\"");
if (rc != RC_SUCCESS) {
vars.$File.logical_name="No PC record for this user";
}
}

Thanks a lot for your help.

Regards,

Ulises
Please use plain text.
Honored Contributor
Vadim Gorda
Posts: 5,531
Registered: ‎11-10-2008
Message 5 of 5 (358 Views)

Re: How to populate source field in link record if query doesn't return records

Hello Ulises,

I am sorry for probable mistypes in code, I was writting script without system from scratch.

 

Glad to hear that it helped you

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