CRM 2013 Javascript get data from another entity based on parameter - javascript

I have a situation that is only for users convenience, but is creating a headache for me.
Scenario:
I have (2) custom entities I am concerned with. (1) called "Job" and (1) called "Job Resource." Each have their own form. Job Resource is an N:1 Relationship to a Job.
"Jobs" is just our custom term for an awarded opportunity.
The "Job Resource" is a choice of multiple persons to be associated with that particular job. Those choices are also parameter driven to show "Is Supervisor."
The request I have is to add a "Point of Contact" on the "Job" form, and make it default the "Job Resource, (where 'Is Supervisor'=yes).
I have tried to use Quick View form, but there is no filtered choice for the supervisor or not. I believe I am left to do this with JavaScript. However, I have only done some simple web resources.
I would picture something like:
function xxx_pointOfContactid_onchange() {
xxxToolkit.Common.writeToConsole("begin xxx_pointOfContact_onchange()");
var jobResourceLookup = Xrm.Page.getAttribute("xxx_pointOfContact").getValue();
var select = "xxx_firstname,xxx_lastname,xxx_issupervisor";
if (jobResourceLookup != null) {
xxxToolkit.Rest.Retrieve(
jobResourceLookup[0].id
, "Resource"
, select
, null
, function (retrievedResource) {
if (retrievedResource.issupervisor == 1) {
if (retrievedResource.firstname != null) Xrm.Page.getAttribute("xxx_firstname").setValue(retrievedResource.firstname);
if (retrievedResource.lastname != null) Xrm.Page.getAttribute("xxx_lastname").setValue(retrievedResource.lastname);
} else {
return;
}
, xxxToolkit.Common.errorHandler
, true //asynchronous
);
}
}
When I tried to place this as onChange event, nothing happens.
Again, I am a JavaScript rookie, so if I apologize in advance for rookie question.
Any help appreciated. Thanks so much!

Related

Is there a way to return cell data as a tooltip in Tabulator (v5.0.7)

I want to start by saying that I am by no means an expert in JavaScript, so apologies in advance if I am missing something obvious.
Example:
I'm trying to create a custom tooltip for column A. Using the data from another cell as the parameter for the output of column A's tooltip.
{title: "title", tooltip: function(cell) {return anotherfunction(cell)}...
When passing 'cell' through as a parameter, it's possible to view the information in the rest of the row console.log(cell._cell) but from what I've discovered, there's no way of accessing the rest of the data.
This is a code pen of the issue that I'm having (i've commented out the console.log(cell._cell.value) in the example, as this will make the table fail to render. So, looking at the browsers console, it's possible to see the data that is returned from console.log(cell._cell).
I've tried to use Tabulators cell.getData(), cell.getRow(), cell.getColumn() etc (and a load of others) but each results in an error.
Codepen
https://codepen.io/lukeorriss/pen/yLzMapg
If someone could please point me in the right direction for accessing the data in another row from a tooltip function, this would be great. Thank you all, in advance.
Tabulator use 2 types of definitions for tooltip .
ColumnComponent (Header Cell)
Cell (Data Cell)
So You have to put a condition for your formatTooltip function
function formatTooltip(cell) {
// Need to open browser console log to view this.
if (cell._cell) {
let { name, email, address } = cell.getData();
return `You are ${name}, your email is ${email} and address is ${address}`;
} else if (cell.type === "ColumnComponent") {
return cell.getField();
}
}
See My Codepen

Check JSON value in a string with JavaScript

In my Rails I have two models, both with a method giving JSON back. One model is rent.rb the other is buy.rb. I also have a map.js, which will show a map with different pins, depending on the model, basically. So one map shows pins with apartments to rent, another - with apartments to buy. So, now I need a tooltip with a different information, depending on buy / rent. So I defined this part (as it's not coming from database), for rent.rb:
information {
...
type: "rent"
}
and for buy.rb with :
information {
...
type: "buy"
}
So now, in my map.js I wish to find out type and depending on what I get show the right information
(type == "rent") ? (show information for rent) : (type == "buy") ? (show information for buy)
But somehow JS won't access this value and won't customize information shown. Unfortunatelly I can't show the code, as it's for work. But maybe I am just using the wrong syntax here ...
You cannot join conditional operators like way you showed. Also you cannot have a function between ? and :
It will be better to do something like this
var rentInformation="some value";
var buyInformation="some other value";
var displayInformation = (type == "rent") ? rentInformation : buyInformation;
somePopupFunction(displayInformation);

Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript

This function buttonBuzz() works inside the Forms of the Entities Account, Contacts and Leads. But not in the Opportunity form.
Mainly because there is no telephone1 attribute. There is however a Contact entity added with "Quick View" in a section with a telephonenumber inside.
I think it can be accessed with the telephone1 as well just not with Xrm.page
Any ideas how i can grab the attribute from inside the "quick view"?
I dont know if the "Quick view" window is a form of an iFrame. And if it is i have no clue how to access it with the Xrm.Page.getAttribute("telephone1").getValue();
function buttonBuzz(exObj) {
var phoneNumber;
// Here i store the "telephone1" Attribute from the current .page
phoneNumber = Xrm.Page.getAttribute("telephone1").getValue();
if (phoneNumber != null) { **Sends phonenumber** } ...
Quick Views display data from a record selected in a lookup field, in this case a Contact. You can query data from related records using the OData endpoint.
You first need to get the Guid of the record selected:
var contactId = Xrm.Page.getAttribute("parentcontactid")[0].id || null;
You would then need to send a SDK.REST request, passing parameters for the Id of the record (contactId), entityName and the columns:
var entityName = "Contact";
var columns = "Address1_Telephone1, FirstName, LastName";
SDK.REST.retrieveRecord(contactId, entityName, columns, null, function(result) {
// Success, logic goes here.
var address1_Telephone1 = result.Address1_Telephone1;
}, function(e) {
console.error(e.message);
});
As well as your JavaScript file, you would need to include the SDK.REST.js file that is included in the MS CRM SDK download within your Opportunity form libraries.
You can pull that field up from the Contact into the Opportunity by creating a Calculated Field, setting it equal to parentcontactid.telephone1
Put the field on the form, and you'll be able to .getAttribute() it like any other Opportunity field (being Calculated, it updates itself whenever the source changes).

pass Algolia id attribute instead of Name Atributre in a post request on Laravel 5.2

Using the Javascript, Vue.js and Typeahead.js way shown by Jeffery Way and Algolia docs to index json objects from the Algolia platform.
Currently when i search for the result i require and hit the submit button, It is passing the name attribute through in the post request.
How is it possible to pass the name and the id attribute or if nescessery just the ID arrtibute would work.
<script>
new Vue({
el: 'body',
data: {
query: '',
users: []
},
ready: function(){
this.client = algoliasearch("MYID", "MYAPI");
this.index = this.client.initIndex('dev_category_list');
$('#typeahead').typeahead(null, {
source: this.index.ttAdapter(),
displayKey: 'name'
});
},
methods: {
search: function(){
if (this.query.length < 3) return;
this.index.search(this.query, function(error, results){
this.users = results.hits;
}.bind(this));
}
}
})
</script>
As a total newcomer the laravel, vuejs and javascript its somewhat difficult to get to grips with the syntax and phrases used when explaining the instructons within the docs so any help would be greatly appreciated.
My indexed objects look like so:
{
"id": "3",
"name": "My Product 3",
"value": "3",
"alternative_name": "Prod 3",
"objectID": "3"
}
Im hoping to pass the value of ID or objectID along with the name attribute in a post request once the user selects the given result from the algolia drop down menu and hits the submit, just the ID would work as mentioned above if its not possible.
Thanks.
--- Update referencing Jerska: ---
Ok so after playing around as a newbie for a little bit i seem to have it working, Im not exactly sure how secure this is or how reliable one would say, Hopefully im not a million miles off from where i need to be. Be good to see what your personal and professional thoughts are.
.on('typeahead:select', function (e, suggestion) {
$('#typeahead').change(function() {
var val = suggestion.id;
$('#st').val(val);
});
I have created a hidden input field and named is 'st' for a demo and on update of the algolia results jquery is using the .change function to append the value to the hidden input fields value. That way the form can be continued and sibmitted as i originally wanted and hoped for, The benefit here is that even if the user is to select a result from algoia drop down menu then continue with the form, If he or she decides they want to go back to the search field and change it, They can do before they submit the form or before any window.location is run, I even thought of using ajax or simply jquery $.post but its working ok the .change
Look forward to hearing your thoughts.
Thanks
If you want to redirect to an item page, the typeahead:select event gives you the selected option :
$('#your-input')
.typeahead(/* ... */)
.on('typeahead:select', function (e, suggestion) {
window.location = suggestion.url;
});
from Algolia redirect to search results
You can access the selected object through the suggestion parameter. You could definitely use something like
window.location = 'YOUR_URL?id=' + suggestion.id + '&name=' + suggestion.name;
This assumes you're using typeahead.js#0.11.
typeahead.js being unmaintained, Algolia recommends to use their own fork of typeahead.js#0.10, autocomplete.js.
Here are the different event names and handlers signatures depending on what library/version you're using:
typeahead.js#0.11: typeahead:select -> function($event, suggestion)
typeahead.js#0.10: typeahead:selected -> function($event, suggestion, datasetName)
autocomplete.js: autocomplete:selected -> function($event, suggestion, datasetName)

JavaScript search not allowing for zero

Please see the Sample Fiddle
If you enter either of the example codes in the search box, you'll get a result that pops up in a jQuery UI Dialog.
The first example is 006.
Here's the code...
if (ccode == 006) {
sarcomment = '006';
sardefinition = 'If you need to make corrections to your information, you may either make them online at www.fafsa.gov, or by using this SAR. You must use your Federal Student Aid PIN to access your record online. If you need additional help with your SAR, contact your school’s financial aid office or visit www.fafsa.gov and click the “Help” icon on the FAFSA home page. If your mailing address or e-mail address changes, you can make the correction online or send in the correction on your SAR. ';
saractionneeded = 'N/A';
}
Immediately after that, you'll see the code for code 030.
Here's the code...
if (ccode == 030) {
sarcomment = '030';
sardefinition = 'We are unable to read all of the information on your FAFSA or SAR because it was damaged. Please review all of the items on this SAR and make any corrections as needed.';
saractionneeded = 'N/A';
}
The set up for the code 006 and 030 are the same. What I've learned here is that any of these search criteria that I create that ends with a 0 (zero), will result in an undefined query.
Not sure how to resolve this and seeking your assistance.
Numbers that begin with a 0 in old & backward compatible versions of JavaScript are octal.
030 = 0*8^2 + 3*8^1 + 0*8^0 = 24
Strict mode turns octal numbers into a syntax error
Here's a suggestion for cleaning up that code. Instead of a long train of if statements — each one of which provides a chance for some subtle bug to creep in — you could instead use an object to map codes onto blocks of information. That would look something like this:
function showc_code(ccode){
var codeTable = {
'006': {
definition: 'If you need to make corrections to your information, you may either make them online at www.fafsa.gov, or by using this SAR. You must use your Federal Student Aid PIN to access your record online. If you need additional help with your SAR, contact your school’s financial aid office or visit www.fafsa.gov and click the “Help” icon on the FAFSA home page. If your mailing address or e-mail address changes, you can make the correction online or send in the correction on your SAR. ',
action: 'N/A'
},
'030': {
definition: 'We are unable to read all of the information on your FAFSA or SAR because it was damaged. Please review all of the items on this SAR and make any corrections as needed.',
action: 'N/A'
},
'040': {
definition: 'Whatever',
action: 'Something something'
},
// ... other codes ...
};
if (codeTable[ccode] != null) {
sarcomment = ccode;
sardefinition = codeTable[ccode].definition;
saractionneeded = codeTable[ccode].action;
}
else {
// unknown code ... do whatever
}
// ... rest of your code to show the dialog ...
}
That way the mapping from code to relevant information is just data, with no "moving parts".

Categories

Resources