I am looking to get the users record type from a certain permission set. I need to first get the userId and then I have a picklist on the user field which can be used to communicate with a crosswalk table to link to the record type.
I have a feeling I'm supposed to use $user but I keep getting errors. Also, program__c is a picklist so I'm not sure if that returns a string.
<script src="/soap/ajax/30.0/connection.js"></script>
<script src="/soap/ajax/30.0/apex.js"></script>
<script type="text/javascript">
setTimeout(function() {
var query1 = sforce.connection.query(select program__c from user where id =: $user.userid);
var query1Result = query1.getArray("records");
var query2 = sforce.connection.query(select Program_record_type__c from Fields_to_Program__c where program__c = query1Result[0].program__c);
var query2Result = query2.getArray("records");
sforce.one.createRecord('Activity__c', query2Result[0]);
if(typeof sforce != 'undefined' && sforce != null) {
sforce.one.createRecord('Activity__c', query2Result[0]);
} else {
window.open('/a01/e', '_self');
}
}, 3);
</script>
Best Answer
You can't use "bind expressions" in JavaScript. You have to actually use normal strings. This should be approximately correct:
You should note that JavaScript is also case sensitive, so make sure your field names, when referenced in JavaScript, are exactly correct.