Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Micro Focus Expert
Micro Focus Expert
510 views

JavaScript Error

Jump to solution

Hi Experts,

I'm trying to sync the status for some requests to the related interaction:

Below is the script:

var $ = lib.c.$;
var _ = lib.Underscore.require();
var _sf = system.functions;
var p = print; 

//var relatedFile = $('request').newFile();

var r = $('request').select("status=\"Closed\" and current.phase=\"Closure\" and submit.date>=\'10/01/18 00:00:00\'").uniqueResult();
// p (r)
var requestID = r.number;
	var rc;
	var relation = new SCFile("screlation");
if ( relation.doSelect( "source=\"" + requestID + "\" and " +
	                      "source.filename=\"request\" and " +
	                      "type=\"Related Interactions\" and "+
	                      "depend.filename=\"incidents\" and "+
	                      "depend.active = 0" ) == RC_SUCCESS )
	                      
p ("Request " + relation.source + " status is " + r.status )
var inc = $('incidents').select('incident.id="'+relation.depend+'"').uniqueResult();
p ("Related Record for Request " + relation.source + " is " + inc.incident_id + " and its status is " + inc.open )
{
inc['open'] = 'Open';
inc['current.phase'] = "Logging"
inc['active'] = "false"

inc.doUpdate();

p ("Related Record for Request " + relation.source + " is " + inc.incident_id + " and its status is " + inc.open)

}

 

********************* Getting the error***************************************************

Script 'A_Sync_Status'  line 21: ERROR TypeError: inc has no properties at char 1

err.JPG

not sure  why the error : inc has no properties at char 1 error is coming.

Please Suggest

Neo Jax

0 Likes
1 Solution

Accepted Solutions
Super Contributor.. bogart Super Contributor..
Super Contributor..

Re: JavaScript Error

Jump to solution

As far as I can see You got no Interaction!

I made some changes (w/o any warranties)!

var $ = lib.c.$;
var _ = lib.Underscore.require();
var _sf = system.functions;
var p = print; 

//var relatedFile = $('request').newFile();

var r = $('request').select("status=\"Closed\" and current.phase=\"Closure\" and submit.date>='10/01/18 00:00:00'").uniqueResult();
if (r) {
	p(r)
    var requestID = r.number;
    var rc;
    var relation = new SCFile("screlation");
    
    if ( relation.doSelect( "source=\"" + requestID + "\" and " +
    "source.filename=\"request\" and " +
    "type=\"Related Interactions\" and "+
    "depend.filename=\"incidents\" and "+
    "depend.active = true" ) == RC_SUCCESS ) {
        p ("Request " + relation.source + " status is " + r.status );
        var inc = $('incidents').select('incident.id="'+relation.depend+'"').uniqueResult();
        if (inc) {
            p ("Related Record for Request " + relation.source + " is " + inc.incident_id + " and its status is " + inc.open )
            inc['open'] = 'Open';
            inc['current.phase'] = "Logging";
            inc['active'] = false;
            rc = inc.doUpdate();
            if (rc == RC_SUCCESS) {
            	p ("Related Record for Request " + relation.source + " is " + inc.incident_id + " and its status is " + inc.open)
            } else {
            	p ("Error updating Interaction: " + RCtoString(rc))
            }
        }
    } 
}

p('finished!')

Some hints:

  • no escape for the date quotes in query beginning and ending with "
  • always check if you really get an object from uniqueResult()
  • active-properties are Booleans ==> true/false without quotes (have a look at the dbdict)
  • encapsulate the code block after the if condition with {}
  • finally: I'm not sure about to manipulate the interaction this way..try to use RuleSets in Process Designer

Good Luck!

Bo

 

View solution in original post

4 Replies
Micro Focus Expert
Micro Focus Expert

Re: JavaScript Error

Jump to solution

Hello Neo Jax,
Thanks for your question.

If I undertstand your script correctly, seems like there is a problem with variable definitions in line 20, which is the root of the error you are seeing.

I suggest you to recheck the following definition to see if the line 21 is being built right.

var inc = $('incidents').select('incident.id="'+relation.depend+'"').uniqueResult();


Hope this helps!

BR!

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution. If you are satisfied with anyone’s response please remember to give them a LIKE by clicking on the Thumb and show your appreciation.

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution. If you are satisfied with anyone’s response please remember to give them a LIKE by clicking on the Thumb and show your appreciation.
0 Likes
Super Contributor.. bogart Super Contributor..
Super Contributor..

Re: JavaScript Error

Jump to solution

As far as I can see You got no Interaction!

I made some changes (w/o any warranties)!

var $ = lib.c.$;
var _ = lib.Underscore.require();
var _sf = system.functions;
var p = print; 

//var relatedFile = $('request').newFile();

var r = $('request').select("status=\"Closed\" and current.phase=\"Closure\" and submit.date>='10/01/18 00:00:00'").uniqueResult();
if (r) {
	p(r)
    var requestID = r.number;
    var rc;
    var relation = new SCFile("screlation");
    
    if ( relation.doSelect( "source=\"" + requestID + "\" and " +
    "source.filename=\"request\" and " +
    "type=\"Related Interactions\" and "+
    "depend.filename=\"incidents\" and "+
    "depend.active = true" ) == RC_SUCCESS ) {
        p ("Request " + relation.source + " status is " + r.status );
        var inc = $('incidents').select('incident.id="'+relation.depend+'"').uniqueResult();
        if (inc) {
            p ("Related Record for Request " + relation.source + " is " + inc.incident_id + " and its status is " + inc.open )
            inc['open'] = 'Open';
            inc['current.phase'] = "Logging";
            inc['active'] = false;
            rc = inc.doUpdate();
            if (rc == RC_SUCCESS) {
            	p ("Related Record for Request " + relation.source + " is " + inc.incident_id + " and its status is " + inc.open)
            } else {
            	p ("Error updating Interaction: " + RCtoString(rc))
            }
        }
    } 
}

p('finished!')

Some hints:

  • no escape for the date quotes in query beginning and ending with "
  • always check if you really get an object from uniqueResult()
  • active-properties are Booleans ==> true/false without quotes (have a look at the dbdict)
  • encapsulate the code block after the if condition with {}
  • finally: I'm not sure about to manipulate the interaction this way..try to use RuleSets in Process Designer

Good Luck!

Bo

 

View solution in original post

Highlighted
Micro Focus Expert
Micro Focus Expert

Re: JavaScript Error

Jump to solution

Hi  bogart ,

Many thanks for the excellent reply. Hints were accurate & really a great learning for me.

Thanks a lot again for your response. it worked well, later i tweaked it few more conditions.

Regards

Neo Jax

0 Likes
Super Contributor.. bogart Super Contributor..
Super Contributor..

Re: JavaScript Error

Jump to solution

You're welcome!

Bo 🙂

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.