Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible to create a Custom Object Based on the string of a text field?

JeffConti
Contributor III

Is it possible to utilize the contents of a text field to create a dynamic custom object based on the individual record?  I want to embed related Tableau Dashboards into a record through a custom object.  In testing, I can easily create a static custom object in the layout and the embedded dashboard shows fine.

 

My thought is to have an admin only text field on the record to place the custom object code and then have a custom object added to the general layout that grabs the contents of that admin only text field and executes the retrieved contents.  Any Idea?

 

The Embed Code for example is:

<script type='text/javascript' src='https://tableau.Testing123.com/javascripts/api/viz_v1.js'></script>

<div class='tableauPlaceholder' style='width: 1200px; height: 777px;'><object class='tableauViz' width='1200' height='777' style='display:none;'><param name='host_url' value='https%3A%2F%2Ftableau.Testing123.com%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='' /><param name='name' value='TestDashboard_0&#47;TestDashboard' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='showAppBanner' value='false' /><param name='filter' value='iframeSizedToWindow=true' /></object></div>‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

 

Thanks,

Jeff

1 ACCEPTED SOLUTION

Accepted Solutions

I figured it out using the following:

<!DOCTYPE html>
<html>
<center>
<emb01>(this is where the variable div will be placed)</emb01>
</center>
<script type='text/javascript' src='https://tableau.yourdomain.com/javascripts/api/viz_v1.js'>
</script>

<script type="text/javascript">
var x = $("#master_DefaultContent_rts_ts4106_s4107_f20979c").text();
document.getElementsByTagName('emb01')[0].innerHTML = x;
</script>

</html>

View solution in original post

5 REPLIES 5

Ilya_Khen
Champion III

Jeff Conti,

 

I am not sure I got the intention correctly, but you can always parse in Custom Object any field from the UI and use it however you want. Retrieval can be either via plain JQuery or CM library. Scott Hagemeyer and David Petty have all covered:

$CM / JavaScript Custom Objects 

Element Ids in Custom Object javascript 

Ilya,

 

Thanks for the references / links you provided.  I read through those and have familiarity of those topics.  Perhaps the following clarifies my challenge (challenge being my limited experience with Java, JQuery, HTML...):

pastedImage_2.png

 

pastedImage_3.png

 

When looking at an individual record, note the EmbedCode01 text field containing the Embed Code for this step.  Then the custom object below it showing the result of that embed code:

pastedImage_6.png

For the purpose of this demonstration, the custom object currently contains the exact same text as the text field.  What I can't figure out is how to write the custom object to obtain the value of the text field and then execute that.  Demonstrating a few of several examples of scripts (and several other variations of these) in the custom object with no success:

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>

<script type="text/javascript">
Sys.Application.add_load(function() {
var Embed01 = $CM.getFieldValue(20979); //grab embedded url
});

</script>

document.getElementById("demo").innerHTML = Embed01;

</body>
</html>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Or this:

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
function myFunction() {
var x = $CM.getFieldValue(20979);
var a = eval("x");
var res = a;
document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Or This:

<script type="text/javascript">
Sys.Application.add_load(function() {
var x = $CM.getFieldValue(20979);
eval(x);
});
</script>‍‍‍‍‍‍

I even tried the following two other methods, but since nothing was returned, I feel like I am not even picking up the text field contents:

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>

<script>
function myFunction() {
var x = $CM.getFieldValue(20979)
return x;
}

document.getElementById("demo").innerHTML = myFunction();
</script>


</body>
</html>
<script type="text/javascript">
Sys.Application.add_load(function() {
var x = $CM.getFieldValue(20979);
return x;
});
</script>

 

Thanks,

Jeff

eval was the right choice, I believe. I have not tried it myself, but checking quickly from stackoverflow, should be possible:

html - execute javascript from textarea - Stack Overflow 

Though, like I said, I did not try myself yet

 

Maybe the value you get from the field is not pure JS, but dirtied with HTML tags or something. You can maybe use also not CM, bud direct call to the element text.

I figured it out using the following:

<!DOCTYPE html>
<html>
<center>
<emb01>(this is where the variable div will be placed)</emb01>
</center>
<script type='text/javascript' src='https://tableau.yourdomain.com/javascripts/api/viz_v1.js'>
</script>

<script type="text/javascript">
var x = $("#master_DefaultContent_rts_ts4106_s4107_f20979c").text();
document.getElementsByTagName('emb01')[0].innerHTML = x;
</script>

</html>

Yep, that is what I also proposed, to take direct element text via JQuery  Good-good