Custom Objects Script - How to load the current y_table ID

lock
push_pin
done
Beantwortet
3

When I use the below script as a trigger "after saving custom object" how do I call the current open custom object record.
I have tried SearchEngine, GetCurrent, EventData URL, ExtraTable Getvalue "ID", GetInputvalue and loads more but just cant find any working sample!
How to you call current open Custom Object Record and Current Company Card from a Button Script & Trigger.
My Script code is below the screenshots.
Any help would be greatly apreciated, I have a Test Environment setup and I believe if the client sees this working they will Migrate to online :-)
 
 
 
 
 
 
____
//Script I'm Using
 
#setLanguageLevel 4;
//Things TeamProject do to the Custom Objects Table
ExtraTable e = getExtraTable("y_membership_db");
 
//  Load the record custom object no ID 82
Bool ok = e.load(82);
 
  // Convert values to numbers correctly
  Integer suma = e.getValue("x_direct_debit_amount").toInteger();
  Integer sumb = e.getValue("x_arrears").toInteger();
  Integer total = suma + sumb;
 
  print(" - Old DD Amount = " + suma.toString());
  print(" - Current Arrears = " + sumb.toString());
  print(" - Calculated Total =  " + total.toString());
 
  //  Save new total which is the VFI DD + arrears value
  e.setValue("x_direct_debit_amount", total.toString());
  e.setValue("x_membership_category", "Member");
  e.save();
// When testing as a Screen Designer Button show this results
  print(" - New DD Amount = " + e.getValue("x_direct_debit_amount"));
  print(" - Company Link = " + e.getValue("x_pub_card_link"));
  print(" - Member Contract ID = " + e.getValue("id"));
  print(" - Membership Contract Status = " + e.getValue("x_membership_category"));
 
// Use the link in custom objects to connect to company card using the contact_id
Integer companyId = e.getValue("x_pub_card_link").toInteger();
 
Company c;
c.load(companyId);
// When testing as a Screen Designer Button show this results
  print(" - Old Membership Status = " + c.getValue("contactCategory"));
 
  // Set the company card to Catergory = "Member" (category id 8)
  c.setValue("contactCategory", "8");
  c.save();
// When testing as a Screen Designer Button show this results
  print(" - Updated Membership Status To Member = " + c.getValue("contactCategory"));
 
//This lists all the Custom Object fields - - -
  // EventData ed = getEventData();
// ed.setNavigateTo("soprotocol:Cust32009/default.aspx?y_membership_db.main.minipreview&y_membership_db_id=74");
 
// SearchEngine se;
// se.addFields("extra_fields", "id,name,field_name,domain,extra_table");
// print(se.executeTextTable());
 
 

14 h, 51 m vor | 11:34 PM

Alle Antworten (3)

Hi Davind, 

From your given example you need to change

from

ExtraTable e = getExtraTable("y_membership_db");
//  Load the record custom object no ID 82
Bool ok = e.load(82);
to

EventData ed = getEventData();
Integer currentId = ed.getInputValue("CustomObjectEntity.CustomObjectId").toInteger();

ExtraTable e = getExtraTable("y_membership_db");
Bool ok = e.load(currentId);

 

 

Let me know if that helped. 

 

6 h, 37 m vor | 07:47 AM
Hi Donatas,
You are an absolute legend. That worked perfectly and allowed me to create the piece below which is very useful.
If you are ever in Ireland, we owe you a few pints of Guinness. Thank you again.

Code used:
//when in a Custom Object Screen - This gets the Current Custom Object ID and can view Table & Field Data
EventData ed = getEventData();
Integer currentId = ed.getInputValue("CustomObjectEntity.CustomObjectId").toInteger();

ExtraTable e = getExtraTable("y_membership_db");
Bool ok = e.load(currentId);

print(" - New DD Amount = " + e.getValue("x_direct_debit_amount"));
print(" - Company Link = " + e.getValue("x_pub_card_link"));
print(" - Member Contract ID = " + e.getValue("id"));
print(" - Membership Contract Status = " + e.getValue("x_membership_category"));

//When in a Company Card Screen - This gets the Current Company Card ID
EventData ed = getEventData();
Integer companyId1 = ed.getInputValue("ContactEntity.ContactId").toInteger();

Company c1;
c1.load(companyId1);
print("Company loaded trying to get ID 1: " + c1.getValue("id") + " -----");
print("Company loaded trying to get ID 1: " + c1.getValue("name") + " -----");


//When in a Person Card Screen - This gets the Current Company Card ID
Customer p;
p.load(personId);

print("Person ID: " + p.getValue("id")
+ " FirstName: " + p.getValue("firstname") + " LastName: " + p.getValue("lastname")+ "\n");
2 h, 55 m vor | 11:29 AM
Hi Donatas, when you in a Company card and running a script, how do you select the highlighted person in the contacts tab while still in the company screen ? As its not showing the ID of the person in the URL becuase you are still on the Company card - Also would you have script code that lists all persons on a company card ? -thanks
2 h, 51 m vor | 11:33 AM

Do note that if you are updating fields on the custom object, you can use the before saving custom object trigger;

EventData eventData = getEventData()

eventData.setOutputValue("CustomObjectEntity.x_direct_debit_amount", "1");
3 h, 32 m vor | 10:52 AM
Nice one, thanks for this David
2 h, 54 m vor | 11:30 AM

Hi Davind, thank you, I appreciate it :) 

May I suggest one thing?

When working with triggers, you might want to try using the following script:

 
EventData ed = getEventData();
log(ed.getInputValues().toJson());
 

After executing the trigger, go to:
SuperOffice Admin → System Design → Debug Log

Search for the most recent entry and open it. This should display all the available values that EventData provides for that specific trigger.

I hope this is helpful! (And no, this tip is not related to your previous suggestion about a beer 😉)

1 h, 48 m vor | 12:36 PM
Super thanks
1 h, 7 m vor | 01:17 PM

Antwort hinzufügen