More interesting support questions to help you customize your EvolutivoFW application.

How can I launch a Generative AI prompt with information from a record?

The conversation went more or less like this:

  • User: I wanted to ask what you have been doing with AI?
  • Me: Nothing. I don't know what to do. What every other CRM-like application is doing seems ridiculous to me. Using all the potential of generative AI to rewrite an email or a comment inside the application seems like a waste of programming effort to me. So I am waiting to have a clear idea of what should be done.
  • User: What I'm looking for is to pass the data of an opportunity, for example, with some field values, and have the AI ​​suggest a sales script to the consultant.
  • Me: That is an interesting idea! The use cases are immense
    • given the data in this potential, tell me how to proceed with the sale
    • given the data in this support ticket, how should I answer next?
    • ...

It should be easy to do too. We create the prompt using the messages module, where you can substitute the variables as needed to parameterize the prompt, then a business action that launches the prompt and shows the result. You can use the credentials module to save the API key. I set out to give it a try.

As I suspected it was easy enough to create a Business Action that merged a message template and showed the result in the browser because we already do that in the email process. This is what the business action looks like:

Prompt Business Action

javascript:ExecuteFunctions('getEmailTemplateDetails', 'templateid=50035').then(function (response) {
    let tpl = JSON.parse(response);
    ExecuteFunctions('getMergedDescription', 'template=' + encodeURIComponent(tpl.body) + '&crmid=$RECORD$').then(function (response) {
        let prpt = JSON.parse(response);
        ldsModal.show('Merged Prompt', prpt, '');
    });
});

Where the template ID (50035 in the example above) is:

Message Template Prompt

And the result looks like this:

Message Template Merged

Now I had to add some code to send the merged template to OpenAI and show the result instead of the merged template. I added two commits, one includes a PHP library to access OpenAI as a service, and the other adds a service inside EvolutivoFW to use generative AI (corebos_genai()) and a function to call that from the browser; genaiPrompt.

The modified business action looks like this:

javascript:ExecuteFunctions('getEmailTemplateDetails', 'templateid=50035').then(function (response) {
    let tpl = JSON.parse(response);
    ExecuteFunctions('getMergedDescription', 'template=' + encodeURIComponent(tpl.body) + '&crmid=$RECORD$').then(function (response) {
        let prpt = JSON.parse(response);
        ExecuteFunctions('genaiPrompt', 'prompt=' + encodeURIComponent(prpt)).then(function (response) {
            let chat = JSON.parse(response);
            ldsModal.show('GEN AI Response', chat, '');
        });
    });
});

Where you can see that I call the new genaiPrompt function and get this result:

AI Prompt Response

Simple and effective. A world of possibilities!

How can I set default values in the creation of a User?

There is, as far as I know, an undocumented functionality of the Field Mapping Business Map. This map serves the purpose of defining field values when creating a record from another record. So we are in record A of some module and we create a new record in module B with the knowledge that we are coming from a certain record. Using the values in the origin record we can do all sorts of calculations or we can simply set values in the new record with any calculation.

This map triggers based on its name, in the case of the example above the name would be A2B, in general, {OriginModule}2{DestinationModule}.

Now the trick. When you set the name of the map the same module like, {ModuleA}2{ModuleA} the application understands that you are trying to set default values for the creation of records in ModuleA. This gives immense power for setting default values for a record based on many conditions. This functionality also works in the Users module, so, if we create a Field Mapping Business Map with the name Users2Users we can set default values for the creation of Users.

Users2Users Map

<map>
  <originmodule>
    <originname>Users</originname>
  </originmodule>
  <targetmodule>
    <targetname>Users</targetname>
  </targetmodule>
  <fields>
    <field>
      <fieldname>first_name</fieldname>
      <Orgfields>
        <Orgfield>
          <OrgfieldName>FIRSTNAME HERE</OrgfieldName>
          <OrgfieldID>CONST</OrgfieldID>
        </Orgfield>
      </Orgfields>
    </field>
  </fields>
</map>

User Default Value

Powerful and customizable!

Photo by Neil Thomas on Unsplash

Previous Post Next Post