lern crmscripts

Hi,

we are planing to swich our Instances from SO Windows to SO Cloud, and implement all til now local Solution with SO vbs Scripts to crmscripts for SO Cloud. So I am newer in crmscripts.

I read the resource about EJScript: https://community.superoffice.com/documentation/SDK/SO.Customer.Service.Support/html/Welcome.htm

different from com-based library, i just would like to know which SO Data Structure will be used in crmscripts, where does such class NSPersonAgent, NSPersonEntity, NSSelectableMDOListItem[] come from? How is to get all current Object like currentcontact...

 

Thanks a lot for your help!

- Jianchun

RE: lern crmscripts

Hello, 

i suggest you take a look at Simens session from expander world last year: 
https://www.youtube.com/watch?v=W922DRL-Cl8&t=0s&list=PLX1weTMg1QOiFYLJ_r6EWY5OtJ4izsFUa&index=11 

This will probably give you are better understanding on how CRMscripts work. 
To begin with you could just create a script like this: 

#setLanguageLevel 3;

EventData dt = getEventData();

Set up some tracing on the script to see what values the EventData contains.
Then load up the entity you want to work with through the NetServer (NSPerson, NSAppointment etc). 

e.g. if i wanted to get the personEntity connected to a sale, then i would do something like this: 

#setLanguageLevel 3;

EventData dt = getEventData();
NSPersonAgent pAgent;
NSPerson pEntity = pAgent.GetPerson(dt.getInputValue("SaleEntity.Person.PersonId"));

NB: I am not 100% sure SaleEntity.Person.PersonId is correct and i havent tested this code-snippet myself, but hopefully it will point you in the right direction. 


//Eivind

Av: Eivind Johan Fasting 12. mar 2018

RE: lern crmscripts

Hi,

You can find the complete reference of classes and methods here:

https://community.superoffice.com/documentation/SDK/SO.Customer.Service.Support/html/Welcome.htm

Otherwise, there are lots of examples in this forum and also various blogs/articles.

Unfortunately, we (still) do not have a "CRMScript in a nutshell" book...

Sverre

Av: Sverre Hjelm 12. mar 2018

RE: lern crmscripts

Hi Eivind and Sverre,

 

Thank you all! That's the points where I can start with!

- Jianchun

Av: Jianchun You 12. mar 2018

RE: lern crmscripts

Hi Eivind,

 

I see your Session about crmscripts, could you share me in crmscripts, how to prevent saving entity when if condition not filled?

Thanks a lot!

 

- Jianchun

Av: Jianchun You 15. mar 2018

RE: lern crmscripts

Jianchun:

You'll need to create a trigger on "Before Save Entity" 

Whenever you write code, you can always hit CTRL + Space you get suggestions on which methods that are available:

 

Remember that you can also trace your scripts, which enables you to see exactly which values you are able to fetch:

 

By following these steps, you can do something like this:

EventData ed = getEventData();
Integer amount = ed.getInputValue("SaleEntity.Amount").toInteger();
if(amount > 1000000)
{
  ed.setBlockExecution(true); 
  ed.setMessage("A sale can't be more than 1 000 000,-"); 
}

Hope this helps :)

Av: Simen Mostuen Iversen 15. mar 2018

RE: lern crmscripts

Hi Jianchun,

Basically, to prevent a save, you need to create a script in one of the "Before save" triggers. This is the hook where you are able to block the save. Here is an example:

https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/customer-service/crmscript-now-available-for-sales-in-online/

Sverre

Av: Sverre Hjelm 15. mar 2018

RE: lern crmscripts

Hello Jianchun. 

I am not 100% sure what you are after, but i will keep working with my previous example.

If i wanted to make sure that i actually have a person connected to the sale, before i edit this personEntity, i would do something like this: 

#setLanguageLevel 3;
EventData dt = getEventData();

// ** Simple check to see if the SaleEntity has a personId connected ** //
if(dt.getInputValue("SaleEntity.Person.PersonId") > 0)
{
NSPersonAgent pAgent;
NSPerson pEntity = pAgent.GetPersonEntity(dt.getInputValue("SaleEntity.Person.PersonId"));

// **here you can set whatever you want on the pEntity you have loaded above ** //

pAgent.SavePersonEntity(pEntity);
}
else
    dt.setValidationMessage("Cannot edit the personEntity because the Sale is not connected to a person!");


Hope this helps!

//Eivind

Av: Eivind Johan Fasting 15. mar 2018

RE: lern crmscripts

Hi Semen,

Thanks for your example! Yes, this setBlockExecution(true) works for me. But the library did not popup if I hit CTRL + Space, it happened nothing, see below the screenshot.

Hi Sverre,

I see your cool example in thread, the same Method, thanks a lot!

Hi Eivind, 

Also thanks for your Scripts! This is also alternative! Bassically waht I want after save, to stop saving Company if any adress-fields not filled, but now I got methods about that from you, thanks again!

And my last Question in this thread, hot to get object of current entity? like currentcontact in vbs for SO Windows.

I try to get rid of as a newer to worrk in crmscripts. Many Thanks for your nice Help!

- Jianchun

Av: Jianchun You 15. mar 2018

RE: lern crmscripts

CTRL + Space should work, but it might vary depending on your OS and browser I guess (Mac = Command + Space).

To get the data from your current entity, you'll need to search in the database, the fastest way would be through SearchEngine:

String contactName;

SearchEngine se;
se.bypassNetServer(true);
se.addField("contact.name");
se.addCriteria("contact.contact_id", "Equals", ed.getInputValue("ContactEntity.id"));
if(se.select() > 0)
  contactName = se.getField(0);

Then you are able to fetch data fields before they're being saved to the database. If you want the address fields, you should probably use the NS class, here's a snippet:

NSContactAgent ContactAgent;
NSContactEntity ContactEntity;
NSAddress CompanyAddress;

ContactEntity = ContactAgent.GetContactEntity(companyId);
CompanyAddress = ContactAgent.GetAddress(companyId);

Map mAddress;
for(Integer i = 0; i < CompanyAddressField.length(); i++)
{
  for (Integer j = 0; j < CompanyAddressField[i].length(); j++)
  {
      String addressType = CompanyAddressField[i][j].GetAddressType();
      String addressName = CompanyAddressField[i][j].GetName();

      // Do Stuff
  }
}
Av: Simen Mostuen Iversen 15. mar 2018

RE: lern crmscripts

Yes Simen,

I can set here my SQL Query to SO Database with Object SearchEngine, and i know the Structure of the whole SO datbase.

more of that i can read here:

https://community.superoffice.com/documentation/SDK/SO.Customer.Service.Support/html/EJScript-Classes-SearchEngine-SearchEngine.htm#!

Av: Jianchun You 15. mar 2018