Question

Set value to a lookup

Hi

I'm trying to do something quit simple but it is not working.

On the event of changing the Account in the LEad section, I want to set the PrimaryContact of the Account as a owner of a lead.

My code is like this:

 

onAccountChanged: function() {

                    var recordId = this.get("Id");

                    

                    var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {

                    rootSchemaName: "Lead"

                    });

                                       esq.addColumn("QualifiedAccount.PrimaryContact.Id", "SalesContact");

                    esq.getEntity(recordId, function(result) {

    if (!result.success) {

        // error processing/logging, for example

        this.showInformationDialog("Data query error");

        return;

    }

    

    this.set("Owner", "SalesContact");

   }, this);

 

When I check the value I got in "SalesContact" I can see the Id, but it won't update the lookup.

What am I missing here ?

 

Like 0

Like

8 comments

It's 

this.set("Owner",result.entity.get("SalesContact"));

Dear Oren,

It is more simple to create a business process that will change owner of Lead on changing of Account in this lead record. So the process will be triggered when the record in "Leads" section is modified and modification is expected in "Account" field. After that you need to read data from this account that was set for lead record. You need primary contact value. And after that you need to use "Modify data" element that will set owner of this lead as value of primary contact taken from "Read data" element. The only minus of this method is that it will be triggered only after saving of lead record. Also you can try the way Jerome has suggested.

Best regards,

Oscar

Jerome BERGES,

Hi Jerome

Thanks for your reply but it's not working.

I checked and the result of: result.entity.get("SalesContact") returns the Id of the record as a string. 

Maybe it has to do with the value I put in the "SalesContact", in this line?:

esq.addColumn("QualifiedAccount.PrimaryContact.Id", "SalesContact");

Maybe I need diferent data type than: QualifiedAccount.PrimaryContact.Id ?

 

 

Oscar Dylan,

Thanks Oscar

A business process can easily work but I need more elegant solution on the client side.

Oren Diga,

In order for the lookup to display the object you've set, it needs to be an object that contains both a value (the ID) and a displayValue (the text Name). 

Modify your esq to retrieve both the QualifiedAccount.PrimaryContact.Id as well as the QualifiedAccount.PrimaryContact.Name. Then, set it in the lookup like this: 

this.set("Owner", {value: result.entity.get("SalesContactId"), displayValue: result.entity.get("SalesContactName")});

 

Ryan Farley,

It's working !!!!

Thanks a lot

Ryan Farley,



How do we set Guid.Empty value to a lookup or remove the lookup data value in a record in server-side scripting?



Say., Owner is a lookup - Filled with a value as "Creatio Account"

There is a custom logic that runs and needs to update this Owner lookup to empty. How to set a Guid.Empty to a lookup?



BR,

Bhoobalan Palanivelu.

Bhoobalan Palanivelu,

You can use the Update class:

var update = new Update(UserConnection, "Contact")
        			.Set("OwnerId", Column.Parameter(null, "Guid"))
        			.Where ("Name").IsEqual(Column.Parameter("Name2"));
    		var cnt = update.Execute();

 

Show all comments