Hi Wian
Try below method. I have added my code into your method. Validate the highlighted relationship name before running
Innovator myInn = this.getInnovator();
string thisId = this.getID();
string thisType = this.getType();
Item thisItem = myInn.getItemById(thisType, thisId);
string srcId = thisItem.getProperty("source_id", "");
Item myRfq = myInn.getItemById("DV_RFQ", srcId);
if (myRfq == null || myRfq.isError()) {
return myInn.newError(string.Format("Unable to get RFQ with ID {0}", srcId));
}
if (myRfq.fetchLockStatus() != 0) {
string rfqNum = myRfq.getProperty("item_number", "");
string lockedBy = myRfq.getPropertyAttribute("locked_by_id", "keyed_name", "?");
return myInn.newError(string.Format("RFQ {0} is locked by {1}, please unlock an try again", rfqNum, lockedBy));
}
// Check we have an attached supplier quotation...
string suppQuoteFileId = thisItem.getProperty("_supplier_quote_file", "");
if (suppQuoteFileId == ""){
return myInn.newError("You must attach a supplier quotation to the RFQ");
}
//Creates the New POR
Item newPoReq = this.newItem("DV_PO_Request", "add");
newPoReq.setProperty("_sage_vendor_id", thisItem.getRelatedItemID());
newPoReq.setProperty("_rfq_id", srcId);
newPoReq.setProperty("_supplier_quote_file", suppQuoteFileId);
newPoReq.setProperty("name", myRfq.getProperty("name", ""));
newPoReq.setProperty("description", myRfq.getProperty("description", ""));
newPoReq = newPoReq.apply();
if (newPoReq.isError()) return newPoReq;
string porId = newPoReq.getID();
// Add the relationship - Begin
HashSet <string> existingPORRel = new HashSet <string> ();
Item PORRel = this.newItem("POR Parts", "get");
PORRel.setProperty("source_id", porId);
PORRel.setAttribute("select", "related_id");
PORRel = PORRel.apply();
if (!PORRel.isError())
{
for (int i = 0; i < PORRel.getItemCount(); i++)
{
existingPORRel.Add(PORRel.getItemByIndex(i).getProperty("related_id"));
}
}
Item RFQfetchRel = myRfq.fetchRelationships("RFQ Parts");
Item RFQgetRel = RFQfetchRel.getRelationships("RFQ Parts");
for (int j = 0; j < RFQgetRel.getItemCount(); j++)
{
Item RFQOneItem = RFQgetRel.getItemByIndex(j);
string relatedId = RFQOneItem.getProperty("related_id");
if (!existingPORRel.Contains(relatedId))
{
Item addPORItem = this.newItem("POR Parts", "add");
addPORItem.setProperty("source_id", porId);
addPORItem.setProperty("related_id", relatedId);
addPORItem = addPORItem.apply();
if (addPORItem.isError())
{
return addPORItem;
}
}
}
// Add the relationship - End
// User Aras PLM Identity to promote the RFQ...
Aras.Server.Security.Identity plmIdentity = Aras.Server.Security.Identity.GetByName("Aras PLM");
bool PermissionWasSet = Aras.Server.Security.Permissions.GrantIdentity(plmIdentity);
try {
string porNum = newPoReq.getProperty("item_number", porId);
myRfq.promote("Accepted", string.Format("Accepted on PO Request {0}", porNum));
}
catch (Exception ex) {
return myInn.newError(ex.ToString());
}
finally {
// Revoke Aras PLM Identity...
if (PermissionWasSet) Aras.Server.Security.Permissions.RevokeIdentity(plmIdentity);
}
string mySQL = "UPDATE innovator.[DV_RFQ_SUPPLIER] SET [_po_request_id] = '{0}' WHERE [id] = '{1}'";
myInn.applySQL(string.Format(mySQL, porId, thisId));
return newPoReq;
Thank You
Gopikrishnan R