how to get heading of business from getInputValue or SearchEngine?

Hi,

in crm script for So Cloud, I want to get from current sale the heading of associated contact's business. with getInputValue:

EventData ed = getEventData();
ed.setMessage(ed.getInputValue("SaleEntity.Contact.Business.Name"));

i can only reach buesiness level. or with SearchEngine:

SearchEngine se;
se.setDBDistinct(true); /* distinct in the query forced */
se.addField("sale.sale_id"); /* Field 0 */
se.addField("sale.heading"); /* Field 1 */
se.addField("sale.contact_id.name"); /* Field 2 */
se.addField("sale.contact_id.business_idx.name"); /* Field 3 */
se.addField("Businessheadinglink.businessheadinglink_id"); /* Field 3 */ 

there is no table Businessheadinglink via SearchEngine. here the sql to get this results if local so database:

select sale.sale_id as SaleID, sale.heading as heading, con.contact_id as ContactID, con.name as Contact, bus.name as Business, busHeading.name as Heading
from crm7.sale sale
inner join crm7.contact con on sale.contact_id = con.contact_id
left outer join crm7.business bus on con.business_idx = bus.business_id
left outer join crm7.businessheadinglink busheadingL on bus.business_id = busheadingL.business_id
left outer join crm7.heading busHeading on busheadingL.heading_id = busheadingL.heading_id
where sale.sale_id = ***

Thanks!

 

RE: how to get heading of business from getInputValue or SearchEngine?

Hi Jianchun, 

if I've understood your request correctly, you want to fetch the Business of a company when you save the sale:

If you trace a script, you will be able to see all the input values that your EventData have access to:

 

By looking through the variables, you will be able to get the SaleEntity.Contact.BusinessName:

 

Which means that by adding this code, you should be able to get the business name:

String businessName = ed.getInputValue("SaleEntity.Contact.BusinessName");

 

If you want to get the business name through the SearchEngine class, you should do something like this:

String contactId = ed.getInputValue("SaleEntity.Contact.ContactId");
String businessName;

SearchEngine seContact;
seContact.bypassNetServer(true);
seContact.addField("contact.business_idx.name");
seContact.addCriteria("contact.contact_id", "Equals", contactId);
if(seContact.select() > 0)
  businessName = seContact.getField(0);

A bit unecessary code, but if you only have the contactId and need the name of the business, this is a way to do it.

Hope this helps :)

Av: Simen Mostuen Iversen 5. feb 2019

RE: how to get heading of business from getInputValue or SearchEngine?

Hiu Simen,

 

Thanks for your Solution! I want the Data a level more in deep, to pick out its Heading of Business. The case is, if new sales created, the Sales Title should be automatically switched to <Heading of Business> <Sale Number> <Sale Title>, with that the user can see immediately, for which type Custom is that sales.

Thanks!

Av: Jianchun You 5. feb 2019

RE: how to get heading of business from getInputValue or SearchEngine?

Ah, so if I've understood correctly, you want the Header text of the Business?

Here's how I would've done it:

String headingName;

SearchEngine seBusiness;
seBusiness.bypassNetServer(true);
seBusiness.addField("BusinessHeadingLink.heading_id.name");
seBusiness.addCriteria("BusinessHeadingLink.business_id.name", "Equals", ed.getInputValue("SaleEntity.Contact.BusinessName"));
if(seBusiness.select() > 0)
  headingName = seBusiness.getField(0).parseSOMultiLanguageString(0);

/*

Language values in the parseSOMultiLanguageString

NoLang = -1,
Norwegian = 0,
English = 1,
German = 2,
Swedish = 3,
Danish = 4,
Dutch = 5,
Global = 6,

*/

 

Hope this is what you were after.

Av: Simen Mostuen Iversen 6. feb 2019

RE: how to get heading of business from getInputValue or SearchEngine?

Hi Simen,

 

yes this works!

Thanks, i lern from that, if more Tables associated by Search Engine.

Av: Jianchun You 6. feb 2019