crm 2011 get the default view id - javascript

Is there a way in CRM 2011 to get the default view id for a custom entity? Using JavaScript I want to dynamically generate a HREF but I don't want to hard code any part of the URL. I know how to get the Server URL and Org name in the link below but not this portion "etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257b"
http://dev:5555/MyOrg/main.aspx?etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257b

You can query public views just like any other entity in CRM. The entity name is SavedQuery and there are properties for returnedtypecode (Entity Name), isdefault, and querytype (the type of query it is).
So with that in mind you can make a query to the OData or Soap endpoints from JavaScript to get the default query for any entity type.

Take a look at: http://msdn.microsoft.com/en-us/library/gg334266.aspx
You should be able to use something like:
var defaultViewId = Xrm.Page.getControl("<lookup field name>").getDefaultView()

Related

How do i use custom post types in separate JS file?

I have made a custom Wordpress post type recepies and I'm trying to use them in a separate JS file but can't find an easy way to access them? (I'm also using JQuery if that makes it easier?)
You can access the data of your custom post types in a javascript file using Rest API and jQuery.
For example, you want to display the ID of your recipe in a div with the class of "the_id" and the title of the recipe in a div with the class of "the_title". Moreover I'm assuming your post type has the name of "recipes" and we just want to get one recipe.
$(document).ready(function() {
$.ajax({
url: "http://yoururl.com/wp-json/wp/v2/recipes?per_page=1"
}).then(function(data) {
$('.the_id').append(data[0].id);
$('.the_title').append(data[0].title.rendered);
});
});
You can reduce the number of posts you are getting with the "per_page" parameter.
In data you can now access everything the Rest API gives you, in the example the ID (via data.id) and the title (via data.title.rendered).
This might interest you: https://developer.wordpress.org/rest-api/reference/
Here the fields you can access by default: https://developer.wordpress.org/rest-api/reference/posts/

how safe is to pass the 'user' to javascript Ajax in laravel?

I already asked about this situation but when you pass the data directly to the view like this:
you get the user with $user = Auth::user(); and then send it to the view with return view ('somepage')->with('user',$user); the browser will get all user data in the view (uername, password, user_id etc..).
And found out it should be safe. Now I am thinking what if you instead are passing it to a script that is in charge of updating the view?
Like this:
return Response()->json($user);
You are firing a json in the wild that gets into the script as data, so can a third party have access to that json data too?
No, you DO NOT want to pass any sensitive data to a script or through JSON. Both of these resources would be viewable from the client side.
You can however, remove the sensitive data from your object before serializing it to JSON and passing to the browser.
In your Eloquent models, add a $hidden property - this property is an array of attributes that will be removed when serializing the model to JSON.
So, your User model will look like:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = ['password'];
}
Then, the password will be removed and not accessible from the client.
Docs: https://laravel.com/docs/5.2/eloquent-serialization#hiding-attributes-from-json

Uploading a img/file to Quickbloxx Custom Objects API?

I'm working on QuickBloxx platform and had a use case where , I need to use some custom data models,I created a custom/class with one text and one file/img as datamodel fields.
I thoroughly followed the following url/documentationlink to quickbloxx custom objects files uploads:
For debug purpose I'm using Post to initiate POST request to Quickbloxx API as follows:
https://api.quickblox.com/data/coupon/file.json?token=mytoken , "coupon", was my object name.I'm able to POST text content to "customer_name" attribute but I cannot POST image to cust_img attribute.
You need to familiarize with this guide:
http://quickblox.com/developers/Javascript#Getting_started
{"errors":{"base":["Required session does not exist"]}} - need to create a session to avoid this error

How to display 100K XML based DOM data on a JSP client page?

I need some help in understanding what to do next.
I need to write a web based search function to find medical records from an XML file.
The operator can enter either part or all of a patient name and Hit Search on the JSP web page.
The server is suppose to then return a list of possible patient names with the opportunity for the operator to go to next page until a possible patient is found. They can then select the person and view more details.
On the Server side
I have an XML file with about 100,000 records. There are five different types of records in the file. (This is roughly about 20,000 x 5 = 100,000).
I have a java class to source the xml file and create a DOM to traverse the data elements found on the file.
-- XML File Begin
100k - XML file outline
<hospital>
<infant key="infant/0002DC15" diagtype="general entry" mdate="2015-02-18">
<patient>James Holt</patient>
<physician>Michael Cheng</physician>
<physician>David Long</physician>
<diagnosisCode>IDC9</diagnosisCode>
..
</infant>
<injury key="injury/0002IC15" diagtype="general entry" mdate="2015-03-14">
<patient>Sara Lee</patient>
<physician>Michael Cheng</physician>
<diagnosisCode>IEC9</diagnosisCode>
..
</injury>
<terminal key="terminal/00X2IC15" diagtype="terminal entry" mdate="2015-05-14">
<patient>Jason Man</patient>
<physician>John Hoskin</physician>
<diagnosisCode>FEC9</diagnosisCode>
<diagnosisCode>FXC9</diagnosisCode>
..
</terminal>
<aged key= xxxx ... >
...
</aged>
<sickness key= xxxx ... >
...
</sickness>
</hospital>
approx 5 ( )x 20,000 = 100K records.
Key and patient are the only mandatory fields. The rest of the elements are Optional or multiple elements.
-- XML File End
Here is where I need help
Once I have the DOM how do I go forward in letting the client know what was found in the XML file?
Do I create a MAP to hold the element node links and then forward say 50 links at a time to the JSP and then wait to send some more links when the user hits next page?
Is there an automated way of displaying the links, either via a Java Script, Jquery, XSLT or do I just create a table in HTML and place patient links inside the rows? Is there some rendering specific thing I have to do in order to display the data depending on the browser used by client?
Any guidance, tutorials, examples or books I can refer to would be greatly appreciated.
Thank you.
I don't know an automatic way to match the type in jQuery, but you can test the attributes, something like verify if a non optional attribute in the object is present:
// Non optional Infant attribute
if(obj.nonOptionalAttribute) {
// handle Infant object
}
Or you may add an attribute to differentiate the types (something like a String or int attribute to test in your Javascript).
if(obj.type == 'infant') {
// handle Infant object
}
#John.west,
You can try to bind the XML to a list of objects (something like Injure implements MyXmlNodeMapping, Terminal implements MyXmlNodeMapping, Infant implements MyXmlNodeMapping and go on and have a List) to iterate and search by the value at the back end or you can pass this XML file to a Javascript (if you are using jQuery you can use a get or a post defining the result type as XML) and iterate over the objects to find what the user is trying to find...
Your choice may be based on the preference to use processor time in the server side or in the client side...

Access action class map in java script within ftl

We need to access an instance map defined in struts action class (it has get/set methods). We need to populated that map dynamically. We generate code to populate the map at runtime using a java script based on some user input. We are using freemarker as template.
Java script code within ftl looks like:
innerHTML += '<input class="isn" onChange="validateTag(this);" name="serialsInp[\'' + listing + '\']" value=""/>';
Here serialsInp is HashMap<String, String> and listing is java script variable. Above code renders a text field. The expectation is when user enters text in this text field, serialsInp should be populated with 'listing' as key and user entered value as value.
Is this the correct way of accessing maps in javascript/ftl?
Solved! The problem was form parameters. The map key in our case contains '-', which is disallowed due to security reasons.
The issue got resolved once we change 'params' interceptor to allow '-' in parameter names by adding following code in struts.xml
<interceptor-ref name="params">
<param name="acceptParamNames">\w+((\.\w+)|(\[\d+\])|(\['\w+(\-\w+)*'\]))*</param>
</interceptor-ref>
Reference 202 & post

Categories