I am learning AngularJS and reading its API
Angular JS Resource
It says "If the parameter value is prefixed with # then the value of that parameter is extracted from the data object " with code example:
var User = $resource('/user/:userId', {userId:'#id'});
var user = User.get({userId:123}, function() {
user.abc = true;
user.$save();
});
I am so slow that after the example I still don't get what the prefixed # means/does. Could someone please give me some examples With and Without the # and elaborate it? Thanks...
Sure.
It means that the value of :userId in your url will be replaced with the id property from the user object when that property is required.
So when is it required? Its required when you are doing something to an existing user, like geting one, updating one. It is not required when you create a user.
In most cases, you will want to have at least one param prefixed with # in your REST url that resource uses (probably the object id). If you dont have one, that means that in order for you to save an instance of an object, you dont need to know anything about where its stored. This implies that its a singleton object. Maybe like a settings object.
Here is your long awaited example:
var User = $resource('/user/:userId/:dogName', {userId:'#id', dogName:#dog});
User.get({userId:123, dog:'Matt'}, function() { .. })
will produce the request: GET /user/123/Matt
Related
When trying to create a new script record within NetSuite, I get the error "Fail to evaluate script: All SuiteScript API Modules are unavailable while executing your define callback". I can't find any real information on what may cause this, and I can't see anything in my custom module that looks suspicious. I can't post the code here as the module is nearly 2,000 lines in length and has some proprietary code in it. As it was with another custom module I built that had issues at the "Upload Script File" stage, if I remove reference to the module in the script the process continues, and then I can go back to the script and return the module reference, wherein everything seems to work correctly afterward.
The only information I found that seemed useful was that the error could be caused by referencing a module outside of the define callback, but that isn't the case. The module has two large objects constructed within, and they're returned from the callback. The only other thing I can think of is that this module calls the other custom module, but I haven't seen anything that says I can't do that.
So, overall, what should I look for to resolve this error? I really cn't seem to find anything useful or that applies to this situation.
EDIT
Ok, so I believe that I discovered the cause is due to the calling of a search function outside of an object/function being returned for the callback. Here's a simplified version of what's happening, since a lot of fields and values are managed:
/**
* custom.module.js
* #NApiVersion 2.x
* #NModuleScope Public
*/
define(['N/search'],
/**
* #param {search} search
*/
function(search) {
var fields = new Array("a","b","c","d","e");
var lValues = search.lookupFields({
type : "customrecord_ng_cs_settings"
, id : "1"
, columns : fields
});
var _values = {
a : lValues.a
, b : lValues.b
, c : lValues.c
, d : lValues.d
, e : lValues.e
};
var _funcs = {
func_a : function() {
// do stuff
}
, func_b : function() {
// do stuff
}
, func_c : function() {
// do stuff
}
};
return {
value : _values
, func : _funcs
};
});
I need to maintain this kind of structure as not everything that gets returned in _values is actually a search/lookup result. Am I going to be forced to encapsulate the construction of this object within a function? And would that cause the lookup to occur every time a value is needed? This is a conversion from a 1.0 script, and this gets loaded and set only once at the beginning so the data is all there the entire time without having to be repeatedly fetched.
So, I see the following options:
Convert the callback output to a function and doing something like
the following at the start of every script:
var _values = customModule.values();
Find some way to rework the code so that any script using the module
can still access values in the following way:
var _a = customModule.values.a;
I'd very much prefer option #2. Is it possible?
You cannot run any SuiteScript module code outside of an entry point. You will need to encapsulate your data retrieval in a function, then invoke that function at the beginning of your entry point.
If you want to avoid multiple fetches, you can leverage memoization in your function, or perhaps N/cache or N/session to store the data.
I am creating a chatbot for an IP firm. Its have an entity named service to have 4 type values. (Patent, Copyright, Trademark, design).
Client: What is a patent?
Bot: (Answer)
Client: how much cost to file it?
How I can know client asking about the patent from the previous context?
I can't use followup-intent in every intent.
Right now I'm using a global variable to get the slot agent.parameters.Service inside fulfillment.
let slot='patent';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function service_typeHandler(agent){
var serv ='';
serv = agent.parameters.Service;
if(serv ===''){
serv=slot;
}
else{
slot=serv;
}
switch( serv ){
case 'patent':
First of all, you're correct on two fronts:
Don't use followup Intents. There are few cases where you actually want followup Intents. Most of the time you want to do this with other means.
Use Contexts. These are (part of) the "other means" in most cases.
In this case, it sounds like you'll have two Intents (and likely more, but this illustrates the point):
"ask.what" - which is the user saying things like "What is a patent?"
"ask.price" - which is the user saying things like "How much to file a patent?", but also "How much to file it?"
For the "ask.what" Intent, you would set an "Outgoing Context". This will automatically capture the parameters that are attached to the Intent. If you want to control it more yourself, you can create your own Context in your webhook and set parameters to whatever value you want. I suggest the latter, because it lets you use a parameter name that you don't use elsewhere. Let's assume that you're using a context named "savedInfo" and that you're setting the parameter to "savedService".
In your "ask.price" Intent, you'd do something similar to what you're doing now. Except that if the Service parameter is empty, get the parameters from the "savedInfo" context and, specifically, the savedService parameter.
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
I have a Parse.com cloud function that sends back a PFObject. In some cases I need to send back values for keys that don't exist in the PFObject. Is that possible?
This is what I tried:
var test = prodAndTitles["products"][0];
test["XOXO"] = "kisses";
prodAndTitles["products"][0] = test;
console.log("XOXO = " + prodAndTitles["products"][0]["XOXO"]);
This prints out kisses as expected.
But back in the app when I try to get the XOXO key it's not there:
NSLog(#"The product's XOXO %#", [self.product objectForKey:#"XOXO"]);
This prints out null.
I also tried changing the product type from PFObject to id, but it doesn't help.
Is there a solution, without going into the datastore class and creating dummy columns?
Here's a complete answer to the problem I faced:
The issue is that none of the notations above works for the Parse.com backbone javascript objects that come from the datastore. This is the notation that does work:
testObject.set('TestProp', 'TestValue');
But this is still only part of the solution. When trying to send the testObject with the newly set property to the client ios app, it causes an error:
Uncaught Tried to save an object with a pointer to a new, unsaved object.
The solution for this is to save the testObject after setting the property:
testObject.save();
This doesn't really make sense because I would have liked to add properties to the testObject and NOT save them to the datastore -- and it's a waste of a database call -- but it seems like Parse won't allow it. Weird.
This is done with setting the correct ACL. The ACL has to be set for the user to be able to read and write. Then you can add new columns. In Cocoa it looks something like this:
PFACL *acl = [PFACL ACL];
[acl setReadAccess:YES forUser:[PFUser currentUser]];
[acl setWriteAccess:YES forUser:[PFUser currentUser]];
[test setACL:acl];
Is it possible to differentiate how documents open in a view on an XPage, depending on the status of a document using the getComponent("programmaticname").getValue() method?
If the status of the document is "Sent" then I want it to open in Edit mode. If the status of the document is "Reviewed" then I want it to open in Read Only mode.
I would like to compute the "openDocAsReadOnly" property in my view. Could someone show me what that code would look like?
This is a working example:
<xp:viewPanel
rows="30"
id="viewPanel1"
var="rowData">
<xp:this.facets>
<xp:pager
...>
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view1"
viewName="yourView">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
id="viewColumn2"
displayAs="link"
columnName="Reviewer"
openDocAsReadonly="#{javascript:rowData.getColumnValue('Status') === 'Responded'}">
</xp:viewColumn>
It is important that
viewPanel has var="rowData" so openDocAsReadonly can reference to current row with rowData....
view column Status has not only "Status" as title but as Programmatic use name too
If all works fine then the URL of your Reviewer column should end with &action=openDocument if Status is "Responded" and &action=editDocument for all other cases.
Maybe the cause for you having trouble to get it to run is much easier: use for test "Responded", not "Reviewed". In your former question you told Status is called "Reviewed", so answers use this. But, your picture here shows "Responded".
Make sure you define a variable name in your viewPanel at All Properties >> data >> var (rowData is a frequently used variable name for that)
This variable holds an object of type NotesXspViewEntry, so it knows a method called .getColumnValue(colName:String), where colName is your Notes view column's programmatic name (I assume it's named "Status").
In consequence your openDocAsReadonly property could hold a code like this:
rowData.getColumnValue("Status")=="Responded"
EDIT:
sorry maybe made a mistake here; probably it doesn't work due to a wrong timing. Instead you could try to override the standard url link by defining it in the viewColumn's pageUrl property. A quick test revealed a code like this (I followed Knut Herrmann's observation):
var d = entry.getColumnValue("Status");
var a="editDocument";
if(d=="Responed") {
a="openDocument"
}
"/yourDocXpage.xsp?documentId=" + entry.getUniversalID() + "&action=" + a
Not really sure though whether this is the best of all solutions...