cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

What type should be the variable obj ?

VladiSlav
17-Peridot

What type should be the variable obj ?

Hello, please tell me what type should be the variable obj ? I found an example of editing a template https://www.ptc.com/en/support/article?n=CS150777 , but there was a problem with the type of variable, tried everything I knew and everything that was recommended, it did not work to pass the test.

 

CODE:

​wt.maturity.PromotionNotice notice = (wt.maturity.PromotionNotice)primaryBusinessObject;
                 wt.fc.QueryResult results = wt.maturity.MaturityHelper.service.getPromotionTargets(notice);
                 while (results.hasMoreElements())
                  {
                          obj = results.nextElement();
                          if (obj instanceof wt.doc.WTDocument)
                          {                                 
         var += obj.getName ()+“,”;         // var  is a global variable
                          }
                     }

 

TESTING:

Checking Syntax...
warning: Supported source version 'RELEASE_7' from annotation processor 'com.microsoft.azure.management.apigeneration.LangDefinitionProcessor' less than -source '1.8'
WfExpression_11.java:57: error: incompatible types: Object cannot be converted to Persistable
obj = results.nextElement();
^
Note: WfExpression_11.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
1 warning

Syntax check complete.

8 REPLIES 8

Didn't the reply by @zsternal-2 in this thread help?

Ok sorry, just saw your reply there. I think there is something wrong with your code. Is this what you wrote after the suggestion from @zsternal-2 

wt.fc.Persistable persistable = (wt.fc.Persistable) resulting.nextElement();

 

If yes, and it did not work, please post the full code.

 

 

 

yadavankur, unfortunately the answer did not help, the error is the same, already many types tried

yadavankur, this is the whole code, nothing else was added

 

wt.maturity.PromotionNotice note = (wt.maturity.PromotionNotice) primaryBusinessObject;
wt.fc.Query Result results = wt.maturity.Maturity Helper.service.getPromotionTargets (note);
    while (results.hasMoreElements ())
    {
        obj = results.nextElement ();
        if (obj instanceof wt.doc.WTDocument)
        {
            var + = obj.getName ()+ ","; / / var-global variable
        }
}

So this is what you are missing 

 

wt.maturity.PromotionNotice note = (wt.maturity.PromotionNotice) primaryBusinessObject;
wt.fc.Query Result results = wt.maturity.Maturity Helper.service.getPromotionTargets (note);
    while (results.hasMoreElements ())
    {
        obj = results.nextElement (); //replace this with below

        wt.fc.Persistable obj = (wt.fc.Persistable) results.nextElement();

        if (obj instanceof wt.doc.WTDocument)
        {
            var + = obj.getName ()+ ","; / / var-global variable
        }
}

 

I find your stack trace intriguing though. Is your Windchill instance on the cloud? I am still confused by the presence of this line "com.microsoft.azure.management.apigeneration.LangDefinitionProcessor"

 

yadavankur, thank you very much, the test passed, but there was one more question, I put a String type for the variable MyValue, but only a comment appeared on the page, then I assigned the value "Test number 6" to the variable var at the end of the code, it appeared, it turns out that the variable var remains empty if you run the code?test.JPG
 
 
 
 

Has the local variable been initialized from and copied into the global variable? These were options when you were creating the local variable.

yadavankur, yes, initialized the variable, maybe the code itself I misunderstood what it does and how to fix it to get the table and display it

initialize.JPG

 

Announcements

Top Tags