Forum Discussion
Hi Gopikrishnan
Thanks so much for your reply, appreciate it :)
This is my main method code to take the RFQ details over to the POR, would it be better to run this as a separate method after the POR has been created or can i just add your code to after the POR is created in my method?
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();
// 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;
Thanks
Wian
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
- Wian_le_Roux5 years agoIdeator III
Hi Gopikrishnan
Thanks so much for your reply! I have tried the code like that with my relationship names entered (RFQ = DV_RFQ_Line and the POR relationship = DV_PO_Parts) but its seems to still not transfer the relationship items over. The DV_PO_Parts relationship still stays empty.
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");
}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.setProperty("classification", myRfq.getProperty("classification", ""));
newPoReq.setProperty("owned_by_id", myRfq.getProperty("owned_by_id", ""));
newPoReq.setProperty("_tandc", myRfq.getProperty("_description", ""));
newPoReq = newPoReq.apply();if (newPoReq.isError()) return newPoReq;
string porId = newPoReq.getID();HashSet <string> existingPORRel = new HashSet <string> ();
Item PORRel = this.newItem("DV_PO_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 = this.fetchRelationships("DV_RFQ_Line");
Item RFQgetRel = RFQfetchRel.getRelationships("DV_RFQ_Line");
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("DV_PO_Parts", "add");
addPORItem.setProperty("source_id", porId);
addPORItem.setProperty("related_id", relatedId);
addPORItem = addPORItem.apply();
if (addPORItem.isError())
{
return addPORItem;
}
}
}// 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;
I did realize i forgot to mention im calling this server method from a clientside Javascript below. But i dont think this should affect it as the main RFQ and POR gets pulled.
var thisId = this.getID();
var thisType = this.getType();
var parItem = parent.thisItem;// This method refreshes grid...
var refreshMyGrid = function () {
if (parent.document.frames.relationships && parent.document.frames.relationships.iframesCollection){
var iFramesCollection = parent.document.frames.relationships.iframesCollection;
iFramesCollection[parent.document.frames.relationships.currTabID].contentWindow.doSearch();
}
};var thisState = parItem.getProperty("state", "");
if (thisState != "Submitted") {
top.aras.AlertError("You can only create a PO Request from state 'Submitted' (current state = '" + thisState + "')");
return this;
}var relItem = this.getRelatedItem();
var vendorName = relItem.getProperty("name", "");if (top.aras.confirm("Create PO Request using supplier " + vendorName + "?")) {
var myItem = this.newItem(thisType);
myItem.setID(thisId);
var newPoReq = myItem.apply("DV_CreatePurchaseRequestSvr");
if (newPoReq.isError()) {
top.aras.AlertError(newPoReq.getErrorString());
return this;
}
else {
refreshMyGrid();
top.aras.uiShowItemEx(newPoReq.node, 'tab view', true);
}
}return this;
Thanks
Wian
- Wian_le_Roux5 years agoIdeator III
I also need to add that the Javascript gets run on a relationship of the RFQ called Sage Supplier. Im not sure if this might affect it?