This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Get value of ItemType when on method for RelationshipType

handpuppet - Friday, September 18, 2015 1:50 PM:

I have an ItemType Item E that has an associated RelationshipType Item ED that references a third ItemType Item D.  ItemType ED appears as a tab on ItemType E's form, and allows users to select an ItemType D. 

We check that Item D is not related to TWO Item E's when user selects an item D under the Item ED tab.  If it is greater than 2, we want to prevent the third from being entered.  Our check is correct but the third is still listed under Item ED tab even when the client side method returns. 

1) Is there a way to prevent the third from being added?

2) While trying to delete the third from Item ED, we need to reference Item E but cannot find a way to get its ID value.  How can we get its ID value?

 



zahar - Tuesday, September 22, 2015 9:20 AM:

If you are trying to limit the amount of times same E & D can be linked using relationship ED you can do it by:

 

  1. Go to Administration->RelationshipType
  2. Find and open for edit your ED relationship
  3. Fill Min Occurs with 0 and Max Occurs with 1

 

To get "parent" item of D use AML:

Item qry = this.getInnovator().applyAML("<AML>" +

"<Item type='ED' action='get' select='source_id'>" +

"<related_id>ID OF ITEM D</related_id>" +

"</Item>" +

"</AML>";

if (!qry.IsError() && qry.getItemCount() > 0) {

string EItemID = qry.getItemByIndex(0).getProperty("source_id", "");

}

 



handpuppet - Wednesday, September 23, 2015 1:06 PM:

thanks for your help.  There are syntax errors I am trying to work out in the code provided.  I will update when I get everything working



handpuppet - Wednesday, September 23, 2015 2:00 PM:

I made the AML itself be contained in a variable and that works.  But when I do applyAML() into an Item, the method no longer works



zahar - Wednesday, September 23, 2015 2:05 PM:

Can you post the error?

 



handpuppet - Wednesday, September 23, 2015 2:12 PM:

There is no error that shows.  The method simply runs and nothing happens.  Like there is no code there. 

If I remove the line "Item qry = this.getInnovator().applyAML" And simply place that code into a var variable, it runs correctly.  I just can't get the AML to return in an Item variable like we need.



zahar - Wednesday, September 23, 2015 2:16 PM:

OK... Can you try to post your full method (both versions)?



handpuppet - Wednesday, September 23, 2015 2:55 PM:

alert("Start");
var innovator = new Innovator();
var documentItem = innovator.getItemById("Drawing",relatedID);
var frameObject = top.document.getElementById("instance");
var docObject = frameObject.contentDocument;
var status = documentItem.getProperty("status");
if(status != 'Approved')
{
   alert('You cannot write an ECO against items that haven't been approved!');

//deletes the currently selected relationship
//removeRelatedItem();
//deleteRelationship(); //this is a call to an Innovator Javascript function

                    //which can be found at scripts/RelationshipsGrid.html

   return;
}


//move stuff around
//moveObjects();

//get the table object
//var tbl =docObject.forms["MainDataForm"].elements["txtTblAffected"];

var textforrow = getOpenECOs();

if (textforrow == "false")
{
 alert("false");
 
 var temp = "<AML>" +

"<Item type='eco_affected_drawings' action='get' select='source_id'>" +

"<related_id>config_id</related_id>" +

"</Item>" +

"</AML>";
 
var tempItm = innovator.applyAML(temp);
 
 alert("Text from AML:" + tempItm);
 
 Item qry = this.getInnovator().applyAML("<AML>" +

"<Item type='eco_affected_drawings' action='get' select='source_id'>" +

"<related_id>config_id</related_id>" +

"</Item>" +

"</AML>";

if (!qry.IsError() && qry.getItemCount() > 0) {

 string EItemID = qry.getItemByIndex(0).getProperty("source_id", "");

  alert("result:" + EItemID);
 }

 //var thisdrawing = documentItem.getProperty("drawing_no");
 
 //var thisid = documentItem.getProperty("id");
 
 //var IDlookingfor = parent.thisItem.getProperty("ID")
 
 //var amltext = "<AML><Item action="get" type="eco_affected_drawings" select="source_id" > " +
  // "<related_id>" + thisid + "</related_id>" +
   //"</Item></AML>";
 

          //var source_id_from_ECO = innovator.applyAML(amltext);
         
 
 //alert("Drawing number is:" + thisdrawing + ", Drawing ID is:" + thisid + ", ECO number is:" + IDlookingfor);
}
else
{
 alert("true");
var tblDiv1  = docObject.getElementById("A339A2724CF55span");
var tblDiv2 = tblDiv1.getElementsByTagName("div")[1];
var tbl = tblDiv2.getElementsByTagName("table")[0];

var lastRow = tbl.rows.length;

//add the row
var row = tbl.insertRow(lastRow);
var cell0 = row.insertCell(0);
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
var cell3 = row.insertCell(3);
var cell4 = row.insertCell(4);

cell0.innerHTML = documentItem.getProperty("drawing_no");
cell1.innerHTML = documentItem.getProperty("manual_rev");
cell2.innerHTML = textforrow;
cell3.innerHTML = documentItem.getProperty("drawing_title");
cell4.innerHTML = "";
}

function getOpenECOs()
{
 alert("checking");
var innovator = new Innovator();
var ecoString = "";
var aml = "<AML><Item action="get" type="ECO" select="eco_number" > " +
          "<or>" +
          "<status>Assigned</status>" +
          "<status>Draft</status>" +
          "<status>Approved</status>" +
          "</or>" +
          "<Relationships> " +
          "<Item action="get" type="eco_affected_drawings" > " +
          "<related_id>" + relatedID + "</related_id>" +
          "</Item> " +
          "</Relationships>" +
          "</Item></AML>";
         
 
var ecos = innovator.applyAML(aml);
 
 alert("There are " + ecos.getItemCount() + " drawings against this ECO");
 
 if (ecos.getItemCount() >= 2)
 {
  alert("This ECO already has two drawings against it.  Cannot relate this ECO to this Drawing.");
  
  return "false";
 }
 else
 {
  
for(var i=0;i<ecos.getItemCount();i++)
{
var eco = ecos.getItemByIndex(i);
var val = eco.getProperty("eco_number");
ecoString = ecoString + val + ",";
}

return ecoString;
 }
}



zahar - Wednesday, September 23, 2015 3:08 PM:

So we are talking about JS method. 

First question, following line:

<related_id>config_id</related_id>

Why config_id as string?

You need to put actual ID and not some string. 

 

next problem:

alert("Text from AML:" + tempItm);

temItm is objet not string - so you need to do something like:

alert("Text from AML:" + tempItm.dom.xml);

 

 



handpuppet - Wednesday, September 23, 2015 3:56 PM:

In the beginning of the method, there is a variable called "relatedID".  I would like to know where this comes from.  It is not defined anywhere, but it works correctly



zahar - Wednesday, September 23, 2015 4:10 PM:

Your method is not running by itself.

There is lots of Aras methods and objects there (before and after) your method.

 

You can write at the top of your method:

debugger;

and check what aras maintain before and after your method

 

 

and enter to debug mode (in IE you need to make sure that you not disable debugging and in FF you need to open debuging console before you enter screen with debugger line)



handpuppet - Tuesday, September 29, 2015 9:01 AM:

Thank you.  I did check the values before the method begins execution.  I still have not found a way to get the value of The "ECO" ItemType with a column "source_id" from the relationship type "eco_affected_drawings"