Update Query to change a lookup value in the result set of records
Hi all,
I need to change a Lookup value in several records according some condition, but it didn't works, if my first time I need to do an aupdate by code using bpmonline. please help
var update = Ext.create( "Terrasoft.UpdateQuery", {
rootSchemaName: "UsrSolicitds3"
} );
/***
* Need to change UsrEstadoCaso lookup field in the result of query
*
* update 'UsrSolicitds3' set 'UsrEstadoCaso' = { value: "88c71452-7487-40aa-9174-b4c04609108c",
* displayValue: "Cerrado" } where Usridmadre = idMadre
*
***/
var filters = update.filters;
var idFilter = Terrasoft.createColumnFilterWithParameter( Terrasoft.ComparisonType.EQUAL,
'Usridmadre', idMadre );
filters.add('IdFilter', idFilter);
update.setParameterValue( "UsrEstadoCaso", { value: "88c71452-7487-40aa-9174-b4c04609108c",
displayValue: "Cerrado" }, Terrasoft.DataValueType.LOOKUP );
var batch = Ext.create( "Terrasoft.BatchQuery" );
batch.add( update );
batch.execute();
},
What I'm doing bad?
Thanks in advance,
Like
Hi Julio,
If you need to change a lookup value on a page dynamically (in JS), you need to use the following syntax
this.set("LookupName", {value:"id", displayValue:"text"});
In queries you need to use the standart syntax
this.set("LookupName", "Id", datatype);
In your case, you need to write
update.setParameterValue("UsrEstadoCaso", "88c71452-7487-40aa-9174-b4c04609108c", Terrasoft.DataValueType.LOOKUP);
Please check the example below
function updateContactCorrespondence(socialAccountId, prevSocialAccountId, callback) { var updateQuery = Ext.create("Terrasoft.UpdateQuery", { rootSchemaName: "ContactCorrespondence" }); var filters = updateQuery.filters; var sourceAccountFilter = Terrasoft.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SourceAccount", prevSocialAccountId); filters.add("IdFilter", sourceAccountFilter); updateQuery.setParameterValue("SourceAccount", socialAccountId, Terrasoft.DataValueType.LOOKUP); updateQuery.execute(function() { if (Ext.isFunction(callback)) { callback(); } }); }
Besides, you always can track a query request with the Network tool of the google chrome console and with the MSSQL profiler.
Thanks Eugene, have some doubts with the code you bring us,
1.- is the code attached OK?,
2.- the method add from filters is the same to method additem?
3.- In the line filters.addItem( "IdFilter", madreFilter ); the first parameter "IdFilter", whats means, where use it?
Thanks
cierraHijas: function( idMadre, callback ) { // Cerrar hijas var updateQuery = Ext.create( "Terrasoft.UpdateQuery", { rootSchemaName: "UsrSolicitds3" } ); var filters = updateQuery.filters; var madreFilter = Terrasoft.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Usridmadre", idMadre ); filters.addItem( "IdFilter", madreFilter ); update.setParameterValue( "UsrEstadoCaso", "88c71452-7487-40aa-9174-b4c04609108c", Terrasoft.DataValueType.LOOKUP); updateQuery.execute( function() { if ( Ext.isFunction( callback ) ) { callback(); } } ); }
Hi Julio,
Yes, your code seems perfectly fine. Here's an additional example from the base product, in case you'd like to be sure:
updateContactAccount: function(callback, contactId) { var recordId = this.get("Id"); var update = Ext.create("Terrasoft.UpdateQuery", { rootSchemaName: "Contact" }); var filters = update.filters; var contactIdFilter = update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Id", contactId); filters.add("contactIdFilter", contactIdFilter); update.setParameterValue("Account", recordId, Terrasoft.DataValueType.GUID); update.execute(function(result) { callback.call(this, result); }, this); },
As for the "IdFilter", it is simply a unique identifier. It allows you to call this fiter any place else in your method.
Thanks Adam,
Wich is the diference between using method add or additem?
Thanks Adam,
Question, how can I indicate in the filter the field is a lookup? in this vay? "Usridmadre".value?
var madreFilter = Terrasoft.createColumnFilterWithParameter( Terrasoft.ComparisonType.EQUAL, "Usridmadre".value, idMadre );
Hi again,
works in this way:
var madreFilter = Terrasoft.createColumnFilterWithParameter( Terrasoft.ComparisonType.EQUAL, "Usridmadre", idMadre );
thanks all
>Wich is the diference between using method add or additem?
When you use Add, you need to specity the name of the item. Then you'll be able to select or delete the item by name.
filters.add("contactIdFilter", contactIdFilter);
If you don't need to delete or modify items in the future, then you can use addItem. It doesn't require a name.
filters.addItem(contactIdFilter);