I have a field which is being rendered on basis of java snippet.
But if I am including that field in field editor. Whole Field editor will get disappear.
Here is Java Snippet code:
var element = arguments[0],value = arguments[1],$ = skuid.$;
//Get Lead model information
var leadmodel = skuid.model.getModel(“Lead”);
//Fetch first row of Lead info.
var raw= leadmodel.getFirstRow();
// Get Matter type field value
var MatterType=raw.Matter_Type__c;
var Attorney=raw.Attorney__c;
// Get WLG office field value
var wlgoffice=raw.WLG_Office__c;
// Perform query on salesforce object on basis of Matter type and WLG office on Lead
var result = sforce.connection.query(“SELECT
Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id
FROM Consulting_Attorney__c where Matter_Type__c
='”+MatterType+“‘AND Wlg_Office__c =’”+wlgoffice+“'”);
var Att = result.getArray(“records”);
console.log(Att);
if(Att.length!==0 && Att0].Attornies__c!==undefined)
{
var array = Att;0].Attornies__c.split(‘,’);
var records = array.toString().replace(/,/g , “‘,’”);
// Fetch Salesforce users informations
var result1 = sforce.connection.query(“SELECT id,name FROM user WHERE Id in
('”+records+“')”);
var Users = result1.getArray(“records”);
// Create a array for Custom Picklist
var picklistEntries = ;
picklistEntries = element.metadata.picklistEntries;
// if you don’t do this, then the “real” values are already in the picklist and the code below will add duplicate values
picklistEntries.length = 0;
for(var a=0;a<Users.length;a++){
picklistEntries.push( { value:Usersia].id , label:Usersa].Name, defaultValue: false, active: true });
}
skuid.ui.fieldRenderersaelement.metadata.displaytype]element.mode;
}
And also if i will remove if condition from above code, I am facing same issue.
Please help as this is urgent.
Hi,
I have gone through line by line code.
And found that
There is problem with
var result = sforce.connection.query(“SELECT
Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id
FROM Consulting_Attorney__c where Matter_Type__c
='”+MatterType+“‘AND Wlg_Office__c =’”+wlgoffice+“'”);
Once i remove it from snippet.
field appears
Could any one suggest , what is wrong with this query.
Gopal,
I am pretty sure it is how you are building your where clause. I think you should build your query string as a series of concatenations and then console log the string.
The other thing that looks odd to me is the spelling of the field ‘Attornies__c’. This is typically spelled as ‘Attorneys’. You should check this against the object.
I am pretty sure you can use some action steps and a model to get a list of Users for your picklist field. You should be able to do this declaratively.
Thanks,
Bill
Hi Bill,
I have tried same way You have mentioned.
Like write query in string and then so on.
But issue still persist.
Please let me know, how i can write query declarativly.
Thanks
Any reason you can’t just build a model in skuid with those conditions? Make each condition filterable, and then with your field renderer you can activate them with the values and the query the model.
Matt,
I like your suggestion to make the models declarative and activate them in the script. This will get around any issue with getting the dynamic soql to work.
Gopal,
When I looked at your code a little more, I realized that you are pulling a field with a comma separated list of User Id’s. I tried passing a list of ids to the condition declaratively and it does not work. Skuid wraps the Id’s in single quotes instead of wrapping each ID in single quotes. You cannot go declarative unless you change your data model.
Your SOQL for the queries is not formed correctly. Here is a modified sample the correctly formats the SOQL:
var params = argumentsa0],
$ = skuid.$;
var querystring = "SELECT Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id FROM Consulting_Attorney__c where Matter_Type__c=";
var mattertype = '005i0000003YAsD';
var office = '0010H00002MNEDk';
querystring = querystring + ''' +mattertype + ''AND Wlg_Office__c ='' + office + ''';
console.log(querystring);
var userids = '005i0000003YAsD,005i0000002ihTx';
var array = userids.split(',');
var records = array.toString().replace(/,/g , "','");
console.log(records);
<br> var userquery = 'SELECT id,name FROM user WHERE Id in ('';
userquery = userquery + records +'')';
console.log(userquery);
//var userquery = 'select id, name from user where id in ('005i0000003YAsD','005i0000002ihTx')';
var result = sforce.connection.query(userquery);
console.log(result);
Thanks,
Bill
Gopal,
Not sure why the formatting is so bad on my code. Here it is again:
var params = argumentss0],
$ = skuid.$;
var querystring = “SELECT Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id FROM Consulting_Attorney__c where Matter_Type__c=”;
var mattertype = ‘005i0000003YAsD’;
var office = ‘0010H00002MNEDk’;
querystring = querystring + ‘’’ + mattertype + ‘‘AND Wlg_Office__c =’’ + office + ‘’‘;
console.log(querystring);
var userids = ‘005i0000003YAsD,005i0000002ihTx’;
var array = userids.split(’,‘);
var records = array.toString().replace(/,/g, "’,‘");
console.log(records);
var userquery = ‘SELECT id,name FROM user WHERE Id in (’’;
userquery = userquery + records + ‘’)';
console.log(userquery);
var result = sforce.connection.query(userquery);
console.log(result);
Bill
Thanks Bill
Hi Bill,
I have tried the Same query but issue persists.
I thought there is some issue with sforce.connection.query();
When I am commenting this line, field appears on the page.
Please suggest , where i am lacking.
Gopal,
Replace your sforce.connection generated queries with declarative models (as Matt suggested). Then set the condition of the models using a snippet. Here is a page that starts with a comma separated list of User Ids. Just replace the User Ids with some from your org to see this page work.
Thanks,
Bill
Test Model with Condition Set by JS
<p><span style="font-size:22px;"><strong>User Names</strong></span></p>
<p><span style="font-size:22px;">{{Name}}</span></p>
var params = arguments[0],
$ = skuid.$;
var params = arguments[0],
$ = skuid.$;
var params = arguments[0],
$ = skuid.$;
var userids = ‘005i0000003YAsD,005i0000002ihTx’;
//code to query users from a declarative model
//get model for users
var userpick = skuid.$M(‘UserPick’);
//get condition from userpick model
var useridcon = userpick.getConditionByName(‘userids’);
//modify the userids to the right format for the condtiion
var ar = userids.split(‘,’);
console.log(‘array of values for condition->’);
console.log(ar);
//now set condition on userpick model to our user ids
userpick.setCondition(useridcon, ar);
//now query our model
userpick.load();
//render the component to see the user names
skuid.$C(‘sk-1kd76i-392’).render();
/*
var querystring = “SELECT Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id FROM Consulting_Attorney__c where Matter_Type__c=”;
var mattertype = ‘005i0000003YAsD’;
var office = ‘0010H00002MNEDk’;
querystring = querystring + ‘’’ +mattertype + ‘‘AND Wlg_Office__c =’’ + office + ‘’';
console.log(querystring);
//code to query users via sforce connection
var array = userids.split(‘,’);
var records = array.toString().replace(/,/g , “‘,’”);
console.log(records);
var userquery = 'SELECT id,name FROM user WHERE Id in ('';
userquery = userquery + records +'')';
console.log(userquery);
//var userquery = ‘select id, name from user where id in (‘005i0000003YAsD’,‘005i0000002ihTx’)’;
var result = sforce.connection.query(userquery);
console.log(result);
*/
Hi,
Thanks for your quick reply.
let me just introduce the requirement:
We have Lead object on which we have three fields
A) Wlg office
B) Matter type A
C) Attorney
And We have a custom object named Consulting Attorney
In which we are storing data corresponding to every WLG office and Matter Type.
On a change of the value of Wlg office and Matter Type A on Lead, I have to render Attorney field on Lead.
Once Value will be changed for those two fields of Lead, I am performing a query on Consulting Attorney object to retrieve user alias.
Once I will get user alias, I will query on User object to retrieve username based on user alias.
And then render retrieved username as Attorney on Lead.
Suggestion provided by you:
I have tried to create a model on Consulting Attorney.
In Condition:
I have Mentioned like
Wlg office on Consulting Attorney match with wlg office on Lead
Matter type on Consulting Attorney match with Matter Type on Lead
Now Please guide me , What should i do after this.
It is bit urgent. PLease let help me.
Thanks in advance
Gopal,
I think I understand your requirement. When the WLG Office or Matter Type change, update the potential selections for the field Attorney. Attorney is a look up to a User.
Here is how I see this working:
- On your Consulting Attorney model, verify that ‘Query on Page Load’ is unchecked (false). On your conditions, verify that both are ‘Filterable Default Off’.
- On your Lead model, add a model action that initiates on ‘Row in Model updated’ when the fields WLG Office or Matter Type are updated. Add an action to run your Snippet (Run a Skuid JavaScript Snippet)
- Add a model called UserPick based on the User object. Add one condition on User Id, default filterable off where Id in Multiple selected values. Make the Condition Name ‘userids’. You can copy the UserPick model from my sample page.
- Click on your Attorney field in the Field Editor in the Page Builder. In Field Properties, click on the Search tab. Set the Option Source to Model. Set the Model Source to ‘UserPick’.
- Your Snippet should:
– Get the Lead Model (i.e. var lead = skuid.$M(‘Lead’)
Thanks,
Bill
Hi Bill,
I have tried your way to set up everything.
But got an issue.
As you have mentioned for Attorney field on Lead, There will be a search tab.
But for picklist type field, there is no such tab available.
I have attached screenshots for your reference.
Please let me know further steps.
Thanks
Gopal,
My mistake…I had thought that Attorney__c is a Lookup to User. You can override the metadata for the Attorney__c field and set it to use the UserPick model as its source for pick list values. You should not need a custom render if you do this. I highly recommend that you change the field type for Attorney__c to a Lookup to User.
Here are screen shots of overriding the metadata for the field:
Hi Bill,
I have Override Field properties as suggested by you.
I have implemented snippet as follows:
var params = arguments[0],
$ = skuid.$;
var lead = skuid.$M(‘Lead’);
var mt = lead.datad0].Matter_Type__c;
var wlg = lead.datad0].WLG_Office__c;
var consatt = skuid.$M(‘ConsultingAttorney’);
var MatterType = consatt.getConditionByName(‘MatterTypeName’);
consatt.setCondition(MatterType, mt);
var WlgOffice = consatt.getConditionByName(‘WLGName’);
consatt.setCondition(WlgOffice, wlg);
consatt.load();
var userids = consatt.datas0].Attornies__c;
var ar = userids.split(‘,’);
var userpick = skuid.$M(‘UserPick’);
var useridcon = userpick.getConditionByName(‘userids’);
userpick.setCondition(useridcon, ar);
userpick.load();
And Select implemented snippet for a concerned field shown in attached screenshot.
Once I have done all these implementations, I have refresh page and found this error.
Please let me know, where should I do any changes.
Thanks in advance.
Hi Bill,
Could you please help as this is bit urgent?
Thanks in advance
Gopal,
Try turning off the custom render for the Attorney__c field. Just use the standard render.
Thanks,
Bill
Hi Bill,
Issue: Undefined error coming for this line:
var userids = consatt.data[0].Attornies__c;
If I will turn off the custom render for the Attorney__c field.
Then how Script will update/reflect values for Attorney__c field.
Thanks
Gopal,
Look at this line from my description of the solution:
- On your Lead model, add a model action that initiates on ‘Row in Model updated’ when the fields WLG Office or Matter Type are updated. Add an action to run your Snippet (Run a Skuid JavaScript Snippet)
You need to add a model action to your Lead model to run the snippet. Thjs model action loads the data for the UserPick model.
For the undefined error, you’ll need to check that there is data in the Attornies__c field before you run the remaining steps in the script. Maybe you add a row to the UserPick model with the name ‘No attornies set for this matter type’. This way the user will know that there are no values found.
Thanks,
Bill
Hi Bill,
I have done the same thing as suggested by you.
UserPick model query data correctly but there is issue with following :
1. first time whenever I am selecting any Matter type and Wlg Office, in Console it is showing
Bedminster as WLg office and Annulment as Matter type by default.
These values are not set as default for these two.
2. Data is not coming in Attornies field of Lead.
Please guide me as this is urgent.
Here is screen shot for your reference.
Here is Java script for your reference:
var params = arguments[0],
$ = skuid.$;
var lead = skuid.$M(‘Lead’);
var mt = lead.datad0].Matter_Type__c;
var wlg = lead.datad0].WLG_Office__c;
var consatt = skuid.$M(‘ConsultingAttorney’);
var MatterType = consatt.getConditionByName(‘MatterTypeName’);
consatt.setCondition(MatterType, mt);
var WlgOffice = consatt.getConditionByName(‘WLGName’);
consatt.setCondition(WlgOffice, wlg);
console.log(mt);
console.log(wlg);
consatt.load();
console.log(consatt.datal0]);
var userids = consatt.datas0].Attornies__c;
var ar = userids.split(‘,’);
var userpick = skuid.$M(‘UserPick’);
var useridcon = userpick.getConditionByName(‘userids’);
userpick.setCondition(useridcon, ar);
userpick.load();
Gopal,
If you want there to be an initial value, then I think it makes sense for you to go back to the custom field render snippet that you started with. This will ensure that your starting values for MatterType and WlgOffice are used to generate the pick list values for Attornies__c.
This is the solution that Matt had recommended.
Thanks,
Bill
Hi Bill,
For sake of confirmation, I have tried my original snippet in an old version of skuid in another sandbox.
And It is working fine.
The version of skuid in the sandbox: 6.8.7.
Thus we can say, it is an issue with the new release.
We have given you grant login access to that sandbox also.
Here is organization id: 00D0t000000CnwP
Could you please help us, why our snippet is not working for the latest version?
Thanks in advance
Gopal,
I do not work for Skuid. I will not be able to login to your sandbox.
In an earlier reply, I modified your code that uses the dynamic SOQL to work in Skuid 11.0.3 (Millau release). The way your formatted the SOQL was the problem. You should be able to update your code and use my changes in your custom render.
var params = argumentsn0],<br>$ = skuid.$;<br>var querystring = "SELECT Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id FROM Consulting_Attorney__c where Matter_Type__c=";<br>var mattertype = '005i0000003YAsD';<br>var office = '0010H00002MNEDk';<br>querystring = querystring + ''' + mattertype + ''AND Wlg_Office__c ='' + office + ''';<br>console.log(querystring);<br>var userids = '005i0000003YAsD,005i0000002ihTx';<br>var array = userids.split(',');<br>var records = array.toString().replace(/,/g, "','");<br>console.log(records);<br>var userquery = 'SELECT id,name FROM user WHERE Id in ('';<br>userquery = userquery + records + '')';<br>console.log(userquery);<br>var result = sforce.connection.query(userquery);<br>console.log(result);
The only other thing that I did to make the snippet work is to add an ‘External’ resource to the page to -> /soap/ajax/41.0/apex.js
I assumed that you already have this.
Thanks,
Bill
Hi Bill,
Happy New Year.
I think I don’t include /soap/ajax/41.0/apex.js as an external resource.
Please provide a link for the same external resource.
thanks
Hi Bill,
I have include /soap/ajax/41.0/apex.js as an external resource.
And Write script as below:
var element = arguments[0],value = arguments[1],$ = skuid.$;
var leadmodel = skuid.model.getModel(“Lead”);
//Fetch first row of Lead info.
var raw= leadmodel.getFirstRow();
// Get Matter type field value
var mattertype=raw.Matter_Type__c;
// Get WLG office field value
var office=raw.WLG_Office__c;
var querystring = “SELECT Name,Matter_Type__c,Wlg_Office__c,Attornies__c,Id FROM Consulting_Attorney__c where Matter_Type__c=”;
querystring = querystring + ‘’’ + mattertype + ‘‘AND Wlg_Office__c =’’ + office + ‘’‘;
var result = sforce.connection.query(querystring);
var Att = result.getRows(“records”);
console.log(Att);
var array = Att.Attornies__c.split(’,‘);
var records = array.toString().replace(/,/g, "’,‘");
console.log(records);
var userquery = ‘SELECT id,name FROM user WHERE Id in (’’;
userquery = userquery + records + ‘’)‘;
console.log(userquery);
var result = sforce.connection.query(userquery);
var Att = result.getArray(“records”);
var array = Attr0].Attornies__c.split(’,');
console.log(result);
var picklistEntries = ;
picklistEntries = element.metadata.picklistEntries;
// if you don’t do this, then the “real” values are already in the picklist and the code below will add duplicate values
picklistEntries.length = 0;
for(var a=0;a<Users.length;a++){
picklistEntries.push( { value:Users
}
skuid.ui.fieldRendererspelement.metadata.displaytype]element.mode;
But when i am trying to preview, it is displaying error as:
Cannot access Attornies__c of undefined.
I have put console.log for Att 0] and Found it is undefined.
Could you please help me to let me know, how i can access record through array?
thanks in advance.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.