I am new to netsuite scripting using javascript. I like to ask, how can I set field mandatory to false using javascript.
Hope that someone can help me.
Note :
If you use nlapiGetField(fieldname) in a client script to return a nlobjField object, the object returned is read-only. This means that you can use nlobjField getter methods on the object, however, you cannot use nlobjField setter methods to set field properties.
However you can use
nlapiSubmitRecord(item_obj, true, true); to ignore mandatory fields on a record.
For more details check out the included parameters in the method.
nlapiSubmitRecord(record, doSourcing, ignoreMandatoryFields);
You are using the correct methods, but setMandatory is not supported in a client script. You can instead try using the exact same code in a User Event, Before Load event handler.
Contrary to the documentation, the nlobjField returned by nlapiGetField is not read-only. Some of the setter methods still work (e.g. setDisplayType) on the client side. You can experiment with which ones do and do not work, but setMandatory is confirmed as not supported on the client side.
Using SS2.0 on a client script you can make it mandatory with this code:
var newSupervisorField = context.currentRecord.getField('custrecord_new_supervisor');
newSupervisorField.isMandatory = true;
This is what worked for me based on the input from #erictgrubaugh and #user3627301
function fieldChanged(type,name){
var metodPayment=nlapiGetFieldText('field_id_to_check');
if ((name == 'field_id_to_monitor_for_change') && (metodPayment=='Financing')) {
var field1 = nlapiGetField('field_id_to_be_disabled');
field1.setDisplayType('disabled');
}
}
You can set mandatory using SuiteScript 2.0 though although it does not works in 1.0.
Below, is an example snippet using client script on customer record
var currentRecord;require(['N/currentRecord'], (currentRecord) => {
var field = currentRecord.get().getField('comments');
field.isMandatory = true;
})
Maybe my answer was already late but for others that came across this post, this is how I do it via client script.
nlapiSetFieldMandatory('yourFieldId', true);
This was already tested because I am using this often. Though some says you cannot set fields to mandatory via client but you can. I did not find any docs about this on netsuite docs though.
Related
I've used the standard instance syntax before without issue, but in this part of my code I can't seem to update an instance I've fetched from the database.
...
const instance = await db.models.Users.findOne({where: {profileName: foundChange.profileName}});
instance.profileName = webUser.username;
await instance.save()
console.log(`Profilename: ${instance.profileName}`);
Console returns the value it was before setting.
I've also tried instance.set(key, value) which similarly has no effects. Am I missing something?
I've found that directly addressing instance.dataValues will change it, but that seems to go against the Sequelize documentation. Will this way update properly?
I think it's because I'm trying to update the primary key actually! Probably a sign I should do some remodelling...
My client has decided to migrate to Office 2016 and porting portions of a business process to that client requires us to offer a replacement to the Document Information Panel, which is no longer available. The Backstage file information area isn't considered a sufficient user experience for the users in question, so we're endeavoring to replace the DIP with a Task Pane app.
This example: https://www.youtube.com/watch?v=LVGqpns0oT8&feature=share shows that the idea is, at least in theory, possible. We considered buying this app but can't find sufficient information to do so.
So we set about attempting to replicate the functionality we need in the DIP. It appears that we can successfully set Document Properties of standard types, such as strings, which looks something like this:
Word.context.run(function(context){
var properties = context.document.properties;
context.load(properties):
return context.sync().then(function(){
properties.title = properties.title + " Additional Title Text"; // once the sync goes off, this works.
return context.sync();
});
});
However, when we try to update an Document Property that's, for example, a Managed Metadata property defined by a SharePoint content type, the value in the proxy object loads and remains changed, but it seems to break its relationship to the actual document property. The code below demonstrates:
Word.context.run(function(context){
var properties = context.document.properties;
var customProperties = properties.customProperties;
context.load(properties):
context.load(customProperties);
return context.sync().then(function(){
var managedMetadataProperty = customProperties.getItem('MngdMetadata');
properties.title = properties.title + " Additional Title Text"; // once the sync goes off, this works.
context.load(managedMetadataProperty);
return context.sync().then(function(){
console.log(managedMetadataProperty.value) // let's say this looks like "10;#Label 1|64d2cd3d-57d4-4c23-9603-866d54ee74f1"
managedMetadataProperty.value = "11;#Label 2|cc3d57d4-4c23-72d4-3031-238b9100f52g"
return context.sync(); // now the value in the javascript object for managedMetadataProperty is updated, but the value in the document does not change.
});
});
});
The document property Managed Metadata Property never changes in the Word UI, nor does a change push back to the SharePoint. Say we save and close the document after making the update, then re-open it. The Property value has not visibly changed, however when we load the proxy object with 'context.load()', the value that's available reflects the changes we made on last run.
I'm unclear about why this would be. It seems like to circumvent this, I would need to make a call back to SharePoint to update the relevant field, but I don't know how I would instruct Word to refresh with the new information from SharePoint.
That's a great question.
The custom properties API gives you access to some built-in properties as well as custom properties. SP-related properties do NOT follow in this category from the API perspective. (and the same is true in VBA/VSTO/COM) To access those you need to use the CustomXmlParts functionalities. Here is a good example on how to use it in the Javascript API.
Also, FYI, the team is working right now in a feature to enable the DIP again, i don't have concrete dates or commitment, but you might get this functionality again out of the box soon.
Have you tried customPropertyCollectionObject.add(key, value) ?
It will replace existing kvp's in the customPropertiesCollectionObject.
Here is the documentation customPropertiesCollection
According to the Google Custom Receiver documentation, if our app performs authentication we can load the customData in json format in our sender application. In my case, I did something similar to the following,
MediaInfo mediaInfo = new MediaInfo.Builder(
"url")
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setCustomData(jsonCustomData)
.build();
Then loaded the mediaInfo like the following,
mRemoteMediaPlayer.load(mApiClient, mediaInfo, true).setResultCallback(....);
In my receiver application, I tried to retrieve the jsonCustomData like the following,
var customData = window.mediaManager.LoadRequestData.customData;
However, it doesn't seem like it's working. I've noticed that in some sample apps, some people use the Cast.CastApi.sendMessage method, and use window.message.onMessage=function(event) where event.data would contain the message. Could someone explain the difference between these two methods? what am I doing wrong?
Notice my receiver code is not wrapped a window.onload function, do I need to?
Thanks for the help!
You may want to hook into mediaManager.onLoad(event) callback (see this for how to do that properly; you need to make sure you call the original onLoad in your implementation). Then, if my memory serves me right, event.data should be of the type cast.receiver.mediaManager.LoadRequestData. If so, event.data.media.customData should have the custom data that you specified in your mediaInfo. If you use customData in your mRemoteMediaPlayer.load() command (instead of the mediaInfo), then it should be accessible in the same callback but through event.data.customData. Please validate this against the receiver API reference to make sure they are correct.
I am trying to find out what the safest way to store data for use when the user clicks on a button.
I know that you can store data in attributes(either the value attribute or a data- attribute) of the button tag like so:
<button type="button" value="1" data-value="1">Click me!</button>
But the problem with this is that the user(probably really only advanced users) can manipulate the value with firebug or some other app and THEN click the button and send over different data. I fully understand that I need to check the input before I try to do anything with the sent data.
I also found out that I could use jQuery's .data() to attach data to dom elements, which seems a bit more useful. I'm not exactly sure how the data is stored, but I assume its harder to manipulate.
What got me really interested in this question was when I was looking through Soundcloud's code in firebug, I saw that none of the "like" buttons had data attached to the buttons. I tried deleting/manipulating elements/data and the buttons still worked. So it got me thinking that they are probably using a similar process to what jquerys data() is doing.
I just want to know if there is a safer way to store data or a way so that the user can't manipulate the data before clicking the button.
Consider this function:
function setupPrivateData(element) {
var private = 1;
element.setPrivate = function ( d ) { private = d; }
element.getPrivate = function ( ) { return private; }
}
When called with some DOM element it will add two methods to it: .setPrivate(val) and .getPrivate().
These are the only methods that will allow you to access and modify that private variable associated with the element.
The user can always manipulate data. Nothing stops an advanced user to access object properties or call a jquery.data() on their own.
Something you could do in vanilla js would be:
var div = document.getElementById("test");
div.something = "hidden value";
div.addEventListener("click", function() {
alert(this.something);
});
<div id="test">click me</div>
The best way would to be a serverside verification if the sent data is valid or not.
Besides that, you could try to wrap your code in an anonymous function to deny the user access to the object:
(function() {
var data = {};
data.something = "test";
})()
But even that fails as soon as the user manipulates your files and adds for instance a debugger statement.
You can obfuscate your javascript but the only validation has to be done on your server. For example, I tried to get the weather from theweathernetwork. They have hidden their API call using multiple files and callbacks. In my opinion, it's just more challenging (funnier) if you want to reverse-engineer their site.
Javascript can't be secure. Never trust user input
If you are logging button clicks, the safest way to keep track is to save and validate on the server side.
For example, when you click a like button on Soundcloud, it makes an HTTP request to Soundcloud's server, records that you clicked the button, and marks it as a favorite. This way, if the same user clicks the button anytime in the future, it can check before incrementing the number of favorites.
The number displayed in the button is also pulled in from the database when the view is rendered.
This is a huge topic, and you have a lot to learn, far too much for a comment here. Anything "stored" in an attribute in the HTML source is absolutely not secure, it can be changed very very easily.
The most common way of dealing with this would be to use a cookie, but even with some effort these can be manipulated.
If security is important, find some way of identifying your users (possibly by IP, but even that isn't fool proof!) and keep the data on your server, linked to a user ID which can be retrieved after the button is clicked.
Can any one please help me how to call dll functions from javascript. while using activexobject I am getting error "automation server cannot create object". Here is my code
var jMyAcctId = document.all.RefNum.value;
var jMyAcctType = document.all.TrxType.value;
var NewObject = new ActiveXObject("HDMFCDV.cdv");
if (NewObject.IsValidID(jMyAcctId,jMyAcctType) == true)
{
document.all.RefNumError.innerText = "";
CnvUp(sel);
document.all.CustFName.disabled = false;
document.all.CustFName.focus();
}
Thanak in advance.
Your JavaScript code is good. I suspect the problem is with the HDMFCDV.cdv ActiveX - either they way you implemented it or they way you registered it.
I'm not familiar with HDMFCDV object. Is that a proprietary object you implemented? Here are few tips to troubleshoot:
Make sure your object is registered (did you run regsrv32?)
Verify HDMFCDF.cdv is in the registry: HKCR\HDMFCDF.cdv
Make sure there is a CLSID
Make sure the class ID is in the registry, and that it points to the DLL implementing your object. HKCR\CLSID{your-guide}\InprocServer32 (REG_SZ)
A very common lookout: have you implemented IObjectSafety. Without this interface, and without this interface returning that it is safe for untrusted caller, IE will refuse to instantiate this object