I have written an html code inside a suitelet and Within the script tags of this html I am calling data from another platform through an api call
Data is stored in a json format in a variable object called info.
How do I retrieve this 'info' value from inside the html code to the outside main suitelet code.
You need to put the information you want in an HTML tag then you put a code on your suitelet that will get all the parameter and you should be able to get that information:
funcntion suitelet(response, request){
if(request.getMethod() == 'GET') {
///render html whith textbox tag and with id=yourparamatername
}
else if(request.getMethod() == 'POST') {
var data = request.getParameter('yourparamatername');
}
}
Related
I am trying to use ol and ul tags in client script pageInit function to apply them on a textbox in netsuite through scripting,they are getting applied on textbox but the record print is throwing errors
function pageInit()
{
var nCustomForm = nlapiGetFieldText('customform');
if(nCustomForm == 'Flow Quote Form')
{
var nFlowQuote = '<ol><li>Example text</li></ol>';
nlapiSetFieldValue('custbody_ed_introduction', nFlowQuote);
}
}
want help.
Have you verified that nCustomForm has exactly that value?
I do this sort of thing fairly regularly but I make sure my inline text field has some default html set on the server and then I use jQuery to find and set the value:
e.g. make sure custbody_ed_introduction is an inline html type field and has a value like
<div id='ed_intro_content'></div>
You can set that as a default on the field or with a Before Load User Event script. Then in your pageInit script
if(nCustomForm == 'Flow Quote Form'){
$('#ed_intro_content').append($('<ol><li>Example text</li></ol>'));
}
I first get the data from sql then pass it into handlebars.
Inside the tag in .handlebars/using view.js, I want to access doctors, but i keep getting[object][object]. I tried json.stringifying it before but still no luck. What is the best way to do this?
umd.matchDocs(val2, function(data) {
console.log(data);
var renderDocs = {
doctors: data
}
res.render("dashboard", renderDocs);
});
After passing object to handlebars, how can I access that object in script tag?
No, not by default. But you can make the data available manually if you want.
Data you pass to handlebars rendering operation is available during the rendering operation only. If you want to be able to access some of that data later in client-side <script> tags, then you can "render" Javascript variables into the <script> tags that contain the desired data.
Remember when rendering data into Javascript variables, you need to render the actual Javascript text (converting to JSON will often create the text for you).
In your specific example, you could do something like this in your rendering code:
umd.matchDocs(val2, function(data) {
console.log(data);
var renderDocs = {
doctors: JSON.stringify(data)
}
res.render("dashboard", renderDocs);
});
And, then in the template:
<script>
var doctors = {{{doctors}}};
</script>
Then, this array of doctors would be available to the Javascript in your page.
In case you haven't seen the triple braces like shown above, that's to tell handlebars to skip any HTML escaping in the data (because this isn't HTML).
I have an editable text web part on a page template. It has a custom HTML envelope before and after the text. How can I hide the whole thing, envelope included, if the editable text is empty?
I need to hide it because the envelope adds stylized markup that shouldn't be visible when there is no text.
Can it be done with a K# snippet on the Visible property? I'm unclear how interrogating a document's property works.
Thanks!
Try this as the "Visible" property:
{% (ViewMode != "LiveSite") || (CMSContext.CurrentDocument.editabletext != "") #%}
Change "editabletext" to whatever you have for your web part control ID.
I'm not familiar with Kentico but these solutions might help. They may not address your problem specifically but might aid in a solution.
CMSEditableImage Extension Method
I came up with a way to check this, I added an extension method for
the CMSEditableImage class that takes the CurrentPage PageInfo object
to check the value of the editable region, don't know if this is the
best way or not, but here's the code.
public static bool IsPopulated(this CMSEditableImage editableImage, PageInfo currentPage)
{
bool isPopulated = false;
string value = currentPage.EditableItems.EditableRegions[editableImage.ID.ToLower()].ToString();
if (!string.IsNullOrEmpty(value))
{
value = value.ToUpper();
isPopulated = (value == "<IMAGE><PROPERTY NAME=\"IMAGEPATH\"></PROPERTY></IMAGE>") ? false : true;
}
return isPopulated;
}
via http://devnet.kentico.com/Forums/f19/fp5/t4454/Empty-CMSEditableImage.aspx
JavaScript Method
The webcontainer needs an id, example:
<h2 id="webpart-header">Headline</h2>
Then I have a small javascript function that is attached in an
external js file:
/* Hide Webcontainer via javascript if empty*/
function hideLayer(element) {
elem = document.getElementById( element );
elem.style.display = "none";
}
Now in the wep part configuration, at no data behaviour, you uncheck the checkbox and call the js function by entering following
script in the no record found text: hideLayer("webpart-header");
Whereby webpart-header the id name of your container is. You could
also have a more complex <div> structure here.
via http://devnet.kentico.com/Forums/f22/fp3/t4180/Webcontainer-and-hide-if-no-data.aspx
I have used the following code in a NetSuite Suitelet to upload and process a file:
function main(request,response){
if (request.getMethod() == 'GET'){
var form = nlapiCreateForm('Item Import Correction', false);
var fileField = form.addField('custpage_file', 'file', 'Select CSV');
form.addSubmitButton();
response.writePage(form);
}else{
try{
var file = request.getFile("custpage_file");
var content = file.getValue();//exception
response.write(content);
}catch(ex){
response.write('Exception:'+ex);
}
}
}
When I select a file and submit it, I get an exception on calling getValue() on nlobjFile. Here is the output of response:
Exception:JavaException: java.lang.NullPointerException: charsetName
However, I replace the getValue() call with some other method of the same object like getSize() or getType(), the code works fine.
I just want to parse a file selected by user in a Suitelet.
getFile() - Returns a file added through the nlobjForm.addField(name, type, label, sourceOrRadio, tab) method. When adding a file field type, you will set the type parameter of 'file'.
Make sure that the field you are referencing to using getFile() do exists in the form.
Calling the setEncoding() method on nlobjFile did the trick for me. I was using Chinese Encoding so this was the code that worked for me
var file = request.getFile("custpage_file");
file.setEncoding('GB18030');// Chinese
var content = file.getValue();//no exception
I am trying to append a string to the body field of a CCK node after it has been submitted or edited. However, I'm having trouble working with the body field in the form alter. My initial attempt was to modify the body field in the submit handler by using the .operator to append a string to the body field.
//Calling this submit function to add string to body.
function appendToBody_submit_function($form, &$form_state) {
$form_state['values']['body'] = array('0' => array('value' => $form['#body'])) . $stringToAppend;
}
However, I can't get this to work, and I'm not sure it's the right way. I am new to Drupal, Can someone point me in the right direction? Should I be using node_api for this?
I assume that you add your custom submit callback to the forms #submit array via hook_form_alter().
If you add it before any other entry in that array (as opposed to just appending it), your callback should be called before the standard submit function. That way, all you need to do is adjust the $form_state['values']['body'] content 'in place', and it will be picked up (and subsequently saved) on further processing by the standard submit callback implicitly:
/**
* Implementation of hook_form_alter()
*/
function yourModule_form_alter(&$form, $form_state, $form_id) {
// Is this a node edit form?
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
// Yes, add custom submit handler *before* already existing ones
array_unshift($form['#submit'], 'appendToBody_submit_function');
}
}
// Custom submit function to add string to body.
function appendToBody_submit_function($form, &$form_state) {
$form_state['values']['body'] = $form_state['values']['body'] . $stringToAppend;
}
I recommend installing the Devel module so you can easily print out the contents of $form_state by placing dpm($form_state); in your method body. I usually start with that to make sure the values are where/what I expect.
// Replace "hook" in the function name with the name of your module.
function hook_submit($form, &$form_state) {
// dpm($form_state); // Debug code to view the contents of $form_state.
$body = $form_state['values']['body'] . ' new string to append';
// Place code to save this data to your database here.
}