I am using code in an aspx page (javascript) that is displayed using the sharepoint 2010 UI framework dialog functions.
However, it throws an error. I can't get at the exact details. But here's the code
function DoReject(rejectype) {
rejecttype = rejectype;
this.clientContext = new SP.ClientContext.get_current();
var targetList = clientContext.get_web().get_lists().getByTitle('Applications');
var qs =window.location.search.substring(1);
var arrs = qs.substring(0,qs.indexOf('&',0)).replace('arr=','').split(',');
for (var i = 0; i < arrs.length;i++) {
k = arrs[i];
if (k != null && k != '') {
try {
this.applicant = targetList.getItemById(k);
applicant.set_item('ApplicationStatus', 'REJECTED');
applicant.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.doNothingReject), Function.createDelegate(this, this.rejectError));
this.applicant = targetList.getItemById(k);
clientContext.load(applicant, 'EMail', 'CrisDBID', 'ApplyJobTitle', 'JobRef', 'BrandId');
clientContext.executeQueryAsync(Function.createDelegate(this, this.DoRejectSuccess), Function.createDelegate(this, this.rejectError2));
}
catch (e) {
alert(e);
}
}
}
}
Note i haven't included the success / error methods, as they are superfluous in this. And the ids return correctly - they are passed into the query string. So the variable k is definitely the id of the list item.
In the error event rejectError, I use the signature
rejectError(e)
Does anyone know how to get the error details from the parameter / whats wrong with the code?
is it possible to call list operations on a page that isn't the native list page using the javascript object model?
thanks in advance
M
What browser do you get the error in? Is the error consistent between browsers? I would recommend that you debug the javascript and look at the variables at the line before it fails to see what's going on.
On a side note the first snippet you pasted looks like a standard train-wreck so if the code fails there it's likely one of these are undefined (if clientContext, get_web() or get_lists() does not return a value). I don't know anything about Sharepoint UI framework so "list operation" etc doesn't say much to me.
Related
Starting with 10.10, Apple started to also support JavaScript for Automation instead of AppleScript but I really have a hard time to understand their JavaScript syntax.
E.g. let's take this easy AppleScript:
tell application "Mail"
set seletedMails to selection
repeat with aMail in seletedMails
set aSubject to subject of aMail
display dialog aSubject
end repeat
end tell
All it does is displaying a dialog with the subject of every selected e-mail in the Mail application. Can't get much simpler than that, can it? Should be easy to do that in JavaScript, right? So here's my code
function main ( ) {
var Mail = Application('com.apple.mail')
Mail.includeStandardAdditions = true
var selectedMails = Mail.selection
for (var aMail of selectedMails) {
Mail.displayDialog(aMail.subject)
}
}
main()
Result:
Error -1700: Can't convert types.
Okay... what did I do wrong? I cannot call selectedMails.length either, same error. selectedMails doesn't seem to be an array at all. Oh, wait, when I do this var selectedMails = Mail.selections (note the plural form!), then I can do selectedMails.length, but it always gives me 0, regardless how many mails I have selected. And when I do this (note, also uses the plural form):
function main ( ) {
var Mail = Application('com.apple.mail')
Mail.includeStandardAdditions = true
var selectedMails = Mail.selections
for (var aMail of selectedMails) {
Mail.displayDialog(aMail.subject)
}
}
main()
It only says:
Error -2700: Script error.
What extremely helpful error messages we get here, not!
You were very close. 😉
Generally, with JXA, you need to use a parenthesis at the end of a command to GET the values. So, you needed:
Mail.selection()
aMail.subject()
Here's the complete script, with my changes:
'use strict';
var app = Application.currentApplication()
app.includeStandardAdditions = true
var Mail = Application('com.apple.mail')
var selectedMails = Mail.selection();
for (var aMail of selectedMails) {
app.displayDialog(aMail.subject());
}
I also added the var app = Application.currentApplication(), as this is considered the best practice by many, and used by Apple in all of their documents.
See Introduction to JavaScript for Automation Release Notes
I have a script to create contacts in my database from the contents of my Google Sheet. It first verifies the contact doesn't exist in my database, then adds the contact. I have thousands of contacts, so to reduce the number of contacts in the existing contacts cache, I filter my contact list by state.
var leadsCache = [];
function createContact(leads){
var leadState = '';
for(var i=0; i<leads.length; i++){
if(leads[i].state != leadState){
leadState = leads[i].state;
populateLeadsCache(leadState);
}
var existingLead = leadsCache[leads[i].email];
if(existingLead === undefined){
var leadId = createNewLead(leads[i]);
}
}
}
This works as expected, until I get to a lead with a new state. The code hangs here:
leadState = leads[i].state;
I don't get an error message. I can set the var to empty like this: leadState = '', but I cannot set the value to something else.
In stepping through the code, I can see that leads[i].state has a new string value.
Why can't I change the value? What is the best way to accomplish my desired results?
UPDATE
I wish there was a better error reporting system for Apps Script. Turns out I had an issue in populateLeadsCache (continuous loop) but the system appeared stuck on leadState = leads[i].state;.
Anyone know how to improve the error reporting in Apps Script?
I am answering the question so it can be closed, but leaving the question here in case someone else has a similar issue that isn't really the issue.
Apps Script does not have robust error reporting tools and the debugger failed to highlight the true issue in another part of the code.
When getting a timeout message in Apps Script be aware that it may not have anything to do with where the code appears to break.
For me, the next line of code populateLeadsCache had an issue if the selected state had too many contacts, which resulted in a continuous loop.
I am debugging a javascript/html5 web app that uses a lot of memory. Occasionally I get an error message in the console window saying
"uncaught exception: out of memory".
Is there a way for me to gracefully handle this error inside the app?
Ultimately I need to re-write parts of this to prevent this from happening in the first place.
You should calclulate size of your localStorage,
window.localStorage is full
as a solution is to try to add something
var localStorageSpace = function(){
var allStrings = '';
for(var key in window.localStorage){
if(window.localStorage.hasOwnProperty(key)){
allStrings += window.localStorage[key];
}
}
return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';
};
var storageIsFull = function () {
var size = localStorageSpace(); // old size
// try to add data
var er;
try {
window.localStorage.setItem("test-size", "1");
} catch(er) {}
// check if data added
var isFull = (size === localStorageSpace());
window.localStorage.removeItem("test-size");
return isFull;
}
I also got the same error message recently when working on a project having lots of JS and sending Json, but the solution which I found was to update input type="submit" attribute to input type="button". I know there are limitations of using input type="button"..> and the solution looks weird, but if your application has ajax with JS,Json data, you can give it a try. Thanks.
Faced the same problem in Firefox then later I came to know I was trying to reload a HTML page even before setting up some data into local-storage inside if loop. So you need to take care of that one and also check somewhere ID is repeating or not.
But same thing was working great in Chrome. Maybe Chrome is more Intelligent.
I recently installed Tridion 2011 SP1 with SDL module Translation Manager enabled.
Everything was working fine. Then I installed the Tridion 2011 Powertools, following the installation procedure.
When trying to reload the GUI (browser cache emptied and modification parameter instanciated for server element in WebRoot\Configuration\System.Config) I'm getting the following Javascript error :
SCRIPT5007: Unable to get value of the property 'getItemType': object is null or undefined
Dashboard_v6.1.0.55920.18_.aspx?mode=js, line 528 character 851
And here is the concerned JS line:
Tridion.TranslationManager.Commands.Save.prototype._isAvailable=function(c,a){var
e=c.getItem(0),f=$models.getItem(e),b=f.getItemType(),d=$models.getItem(this.getTmUri ())
The preceding Javascript lines are dealing with other TranslationManager commands, so I suppose it is a kind of TranslationManager commands registration or somehting.
Trying to browse my Tridion publications by selecting any folder/strucutreGroup will also give the same error and the right frame (content frame) will not display any Tridion items but simply display:
Loading ...
Has anyone already experienced similar issue ?
For now I have no other choice than commenting out the Powertools sections file
Tridion_Home\web\WebUI\WebRoot\Configuration\System.Config
Thank you,
François
Strange thing here is that it refers to Save command which is not intended to be called or used from Dashboard.
I`d suggest to disable JS minification (JScriptMinifier filter in System.config), as it will probably show more correct details.
Another useful thing would be this error call stack.
--
I was not able to reproduce an issue from initial question, but had following error when I installed PT:
PowerTools is not defined
which appears in
*\PowerTools\Editor\PowerTools\Client\Shared\Scripts\ProgressDialog\ProgressDialog.js where it tries to register PowerToolsBase namespace, instead of PowerTools.
I`ll be surprised if adding
Type.registerNamespace("PowerTools");
at the top of the file will fix a problem, as in my case it was breaking entire GUI no matter if TM included or no.
I did check *\PowerTools\Editor\PowerTools\Client\Shared\Scripts\ProgressDialog\ProgressDialog.js, but the line
Type.registerNamespace("PowerTools");
was already there, so not the problem here.
Also, I disabled the JS minification. Here are the main methods the UI is loading before getting the error:
...
PowerTools.Commands.ItemCommenting.prototype.isValidSelection = function (selection) {
//Use the existing Save command from the CME
return $cme.getCommand("Save")._isEnabled(selection);
}
...
/**
* Executes this command on the selection.
* Override this method to implement the actual functionality.
* #param {Tridion.Core.Selection} selection The current selection.
*/
Tridion.TranslationManager.Commands.SendForTranslation.prototype._execute = function SendForTranslation$_execute(selection)
{
var selectedItems = selection.getItems();
if (selectedItems.length == 1)
{
var job = $models.getItem(selectedItems[0]);
if (job)
{
if (job.isLoaded())
{
job.saveAndSend();
}
else
{
$log.warn("Unable to send an unloaded job?! {0}".format(job.getId()));
}
}
else
{
$log.warn("Unable to execute save-and-send-for-translation for this selection: {0}".format(selectedItems));
}
}
else
{
$log.warn("Unable to save-and-send-for-translation multiple items at a time.");
}
};
...
Tridion.TranslationManager.Commands.Save.prototype._isAvailable = function Save$_isAvailable(selection, pipeline)
{
var itemUri = selection.getItem(0);
var item = $models.getItem(itemUri);
var itemType = item.getItemType(); !!!!!!!!! fails on this line !!!!!! item is null or not an object
var config = $models.getItem(this.getTmUri());
if (pipeline)
{
pipeline.stop = false;
}
if (config && config.hasChanged() && (itemType == $const.ItemType.CATEGORY || itemType == $const.ItemType.FOLDER || itemType == $const.ItemType.STRUCTURE_GROUP || itemType == $const.ItemType.PUBLICATION))
{
if (pipeline)
{
pipeline.stop = true;
}
return true;
}
return this.callBase("Tridion.Cme.Command", "_isAvailable", [selection, pipeline]);
};
Ok. It`s clear now.
PowerTools.Commands.ItemCommenting is used in Dashboard Toolbar.
This command uses Save to check its availability.
In the same time TM thinks that "Save" will only be used on an ItemToolbar.
The difference between this toolbars which cause an issue is that Dashboard view could have any-length selection, when Item view will always have selection having one item (currently opened).
Opening empty dashboard selection is not yet made, ItemCommenting tries to check its availability, by calling Save, which calls all its extensions. And so far as selection is empty
var itemUri = selection.getItem(0);
will return null, as well as
$models.getItem(null)
What you can do, is to remove ItemCommenting extension command as it is done in tridion powertool trunk editor.config.
http://code.google.com/p/tridion-2011-power-tools/source/browse/trunk/PowerTools.Editor/Configuration/editor.config?spec=svn942&r=903 [592]
I have a very unique situation.
We use a Cisco Web VPN (don't know the exact name) here at work.
If I try to use the web pages I've developed, the javascript is broken.
I have tracked it down to this:
When using the Cisco Web VPN it will actually rewrite some of the HTML/JavaScript code.
For instance, at the very beginning of the source it has stuck the following:
<script id='CSCO_GHOST' src="/+CSCOL+/cte.js"></script>
This is directly after the <html> begin tag (and not inside the <head> tags).
Inside of that source, cte.js, there is an error. That error is causing jQuery to not function properly. cte.js is part of Cisco's product and is totally out of my control.
I know how to capture errors with the windows.onerror but that is not working for this situation. The error is occurring before my scripts are loaded into the page.
Any ideas on how to suppress this error or work around such a thing?
I had my <script> tags in the <head> and then moved them to the bottom of the <body> and in neither place does it make a difference.
UPDATE:
After a bit more looking, it is something in jQuery. I commented out the <script> tag for jQuery and the error did not happen. Uncommented, the error came back.
This is what I had to do to fix the problem. I created a JS file in my web project with the following code:
if ( typeof SegmentHtml != "undefined" ) {
SegmentHtmlParam.prototype['filter'] = function() {
var name = null;
var value = null;
for (var i = 1; i < this._tokens.length; i++) {
var token = this._tokens[i];
if (token.type === ATTR_NAME) {
name = csco_g_buffer.substring(token.first_index, token.last_index).toUpperCase();
} else if (token.type === ATTR_VALUE) {
value = csco_g_buffer.substring(token.first_index, token.last_index);
};
};
var need_processing = false;
if (ParserClsidName) {
var tmp = ParserClsidName[this._clsid];
if (tmp) {
var proc = tmp[name];
need_processing = typeof proc != 'undefined';
};
};
/**
* ERROR ON NEXT LINE: name is null
*/
if (name!=null && name.toLowerCase() == "csco_proto") {
this._parent['csco_proto'] = value;
};
if (need_processing) { this._parent[name] = value; };
};
};
This is the FIRST javascript file I include in my HTML file.
<script type="text/javascript" src="js/jQueryCiscoKludge.js"></script>
I am running into this issue as well. It is really messed up for Cisco to just rewrite JS code like that, assuming it'll work for every single code on the web. There are some serious irreversible consequence like scope loss that will screw everything up. Who in their right mind would do that in the name of "security"? And what is preventing us from overriding the JS code they have injected?