JSX/Photoshop: Selecting Initial History Snapshot - Looking for a shorter way - history

I have a piece of code that selects the initial state (snapshot) of the active document.
I wonder if there exist a short way to achieve the same goal.
Here is the actual script:
var myDoc = app.activeDocument.name;
var doc = app.activeDocument.historyStates.length;
alert("History States : " + doc);
function firstStep(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('SnpS'), myDoc);
desc1.putReference(cTID('null'), ref1);
executeAction(cTID('slct'), desc1, dialogMode);
alert("Selected Initial State");
};
firstStep();
Thanks in advance

Something along these lines should work for you:
docRef.activeHistoryState = docRef.historyStates.getByName('Snapshot 0');

Related

Validate In-Line Edits in Netsuite

I need to validate inline editing in NetSuite.
I already have a Client Script in place that works great when editing the record normally.
I tried adding a User Event script that on the before save function that validates the record, but it appears this is ignored with inline editing.
Has anybody ran into this before?
Any insight you can provide would be helpful. Thanks!
Edits:
The relevant code from the UE script:
function beforeSubmit(type){
if (type == "create" || type == "edit" || type == "xedit") {
var status = nlapiGetContext().getSetting("SCRIPT", "...");
var amount = Number(nlapiGetContext().getSetting("SCRIPT", "..."));
var nr = nlapiGetNewRecord();
var entitystatus = nr.getFieldValue("entitystatus");
var projectedtotal = Number(nr.getFieldValue("projectedtotal"));
if (entitystatus == status && projectedtotal >= amount) {
var statusText = nr.getFieldText("entitystatus");
var message = "ERROR...";
throw nlapiCreateError("...", message, true);
}
}
}
This applies to the opportunity record.
The field being validated is Projected Total with id projectedtotal.
My mistake, I misunderstood how xedit handled nlapiGetNewRecord(). Calling nlapiGetNewRecord when in xedit only returns the edited fields, not the entire record. Thus, the if statement was never true in xedit mode, because either the amount or the status would be null (it was very unlikely the user would edit both at the same time, and validation relies on both these fields' values).
I edited the code to lookup the field value if it is not present in the new record. Now everything works as expected!
Thanks everyone for the help!
For reference, the corrected code is below.
function beforeSubmit(type){
if (type == "create" || type == "edit" || type == "xedit") {
var status = nlapiGetContext().getSetting("SCRIPT", "...");
var amount = Number(nlapiGetContext().getSetting("SCRIPT", "..."));
var nr = nlapiGetNewRecord();
//Attempt to get values normally
var entitystatus = nr.getFieldValue("entitystatus");
var projectedtotal = Number(nr.getFieldValue("projectedtotal"));
var id = nr.getId();
//If values were null, it's likely they were not edited and
//thus not present in nr. Look them up.
if(!entitystatus){
entitystatus = nlapiLookupField("opportunity", id, "entitystatus");
}
if(!projectedtotal){
projectedtotal = Number(nlapiLookupField("opportunity", id, "projectedtotal"));
}
if (entitystatus == status && projectedtotal >= amount) {
var message = "ERROR...";
throw nlapiCreateError("101", message, true);
}
}
}
In your user event are you checking the value of the type parameter. For inline editing, the value of the type is 'xedit'.

Creating dynamic customer group using suite script

I am trying to create dynamic customer group using suite script in Net suite, I am trying below code but always getting
system INVALID_KEY_OR_REF
Invalid savedsearch reference key 21.
I have checked it is valid save search, Please help I am doing something wrong.
function createDynamicGroup(savedSearchId, groupName) {
var saveSearchObj = nlapiLoadSearch('customer', savedSearchId);
var initValues = new Array();
initValues.grouptype = 'Customer';
initValues.dynamic = 'T';
var goupRecObj = nlapiCreateRecord('entitygroup', initValues);
goupRecObj.setFieldValue('groupname', groupName);
goupRecObj.setFieldValue('savedsearch',saveSearchObj.getId());
nlapiSubmitRecord(goupRecObj);
}
You need group type = 'CustJob' as well as using a public search id:
function createDynamicGroup(savedSearchId, groupName) {
var saveSearchObj = nlapiLoadSearch('customer', savedSearchId);
var initValues = {
grouptype: 'CustJob', // <-- use this
dynamic: 'T'
};
var goupRecObj = nlapiCreateRecord('entitygroup', initValues);
goupRecObj.setFieldValue('groupname', groupName);
goupRecObj.setFieldValue('savedsearch', savedSearchId);
return nlapiSubmitRecord(goupRecObj);
}

XPages - using POI 4 XPages and it errors on $ symbol exporting to Word/PDF

I am using the splendid POI4Xpages add-on for my Xpage. It does very well mapping the web page to the Word or PDF, but I have noticed it bombs when there is a dollar sign ($) within any of the fields on the Xpage/Notes document.
Right now, my workaround for users is to substitute USD in place of the $ symbol, but my users and I would like it to handle the $.
I enclosed the error dump below.
Suggestions for where to begin (and end) are much appreciated. Thank you in advance.
POI 4 XPages -> ERROR
--------------------------------------------------------------
Error : Error during Documentgeneration
POI LIB : 1.2.6.201312211419
StackTrace:
java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:724)
at java.util.regex.Matcher.replaceAll(Matcher.java:824)
at java.lang.String.replaceAll(String.java:1591)
at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks2Run(DocumentProcessor.java:129)
at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks 2Paragraph(DocumentProcessor.java:118)
at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks 2Table(DocumentProcessor.java:110)
at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks 2Document(DocumentProcessor.java:84)
at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processDocument( DocumentProcessor.java:193)
at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.generateNewFile( DocumentProcessor.java:143)
at biz.webgate.dominoext.poi.component.containers.UIDocument.processAjaxRequest( UIDocument.java:208)
at biz.webgate.dominoext.poi.component.actions.DocumentGenerationServerAction.in voke(DocumentGenerationServerAction.java:48)
at com.ibm.xsp.application.ActionListenerImpl.processAction(ActionListenerImpl.j ava:60)
at javax.faces.component.UICommand.broadcast(UICommand.java:324)
at com.ibm.xsp.component.UIEventHandler.broadcast(UIEventHandler.java:366)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.extlib.component.layout.UIVarPublisherBase.broadcast(UIVarPublish erBase.java:185)
at com.ibm.xsp.component.UIViewRootEx.broadcast(UIViewRootEx.java:1535)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:307)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:428)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase .java:94)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96)
at com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:2 56)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:228)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103 )
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(Compone ntModule.java:576)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentMo dule.java:1335)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invoke Servlet(ComponentModule.java:853)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doServ ice(ComponentModule.java:796)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentMo dule.java:565)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule .java:1319)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:66 2)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironme nt.java:357)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment .java:313)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.jav a:272)
We had this same issue and basically did a hack like below to prefix a $ if we found a decimal. Hope this helps out.
function process(xwpfdocument){
try{
// Get POI Document
var x = xwpfdocument;
var tables:java.util.Iterator = x.getTablesIterator();
while(tables.hasNext()){
var t = tables.next();
var numRows = t.getNumberOfRows();
// Loop Through All Rows
if(numRows>0){
for(var row=0; row<numRows; row++){
var cellList:java.util.List = t.getRow(row).getTableCells();
var numCells = cellList.size();
// Loop through all Cells
for(var cell=0; cell<numCells; cell++){
var c = cellList.get(cell);
var paragraphs:java.util.List = c.getParagraphs();
// Loop through all Paragraphs
for(var para=0; para<paragraphs.size();para++){
var p = paragraphs.get(para);
var runs:java.util.List = p.getRuns();
// Loop through all Runs
for(var r=0;r<runs.size();r++){
var run = runs.get(r);
var txt=run.getText(0);
if(txt.indexOf("<NL>")>-1){
var newRun = p.createRun();
var newTxt = txt.split("<NL>");
for(var n=0; n<newTxt.length; n++){
// Add New Runs with Breaks
var prefix = "";
if(newTxt[n].indexOf(".")>-1){
prefix = "$";
}
newRun.setText(#Text(prefix+newTxt[n]));
newRun.addBreak();
}
//Delete old run
//p.removeRun(0);
} else { //added for cases with only one account
var newRun = p.createRun();
var prefix = "";
if(txt.indexOf("%")>-1) { //added so SS002, SS003, and SS004 keep the %, added from the Letter.getBookmarkAPR function, rather than prepending a $
//nothing required
} else if(txt.indexOf(".")>-1){
prefix = "$";
}
newRun.setText(#Text(prefix+txt));
}
//Delete old run
p.removeRun(0);
}
}
}
}
}
}
} catch(e){
// Write to Log
system.out.println(e.getLocalizedMessage());
}
//Done
return;
}
Christian Güdemann posted a new build that addressed the $ character in the middle of a text field issue.
http://www.webgate.biz/ftp/openntf/POI4XPages/snapshot/biz.webgate.dominoext.poi-1.3.0-SNAPSHOT.zip
Btw there is a mailinglist in place to be informed about development builds:
http://mm.wgcdev.ch/mailman/listinfo
Thank you for your help, Dwain and Christian!

CRM 2011 Retrieving lookup

I'm new in CRM development. I know a basic thing like "best practice for crm 2011"
I wanna understand now how to work with lookup fields. And I think I chose the easiest way for my self.
I have an costum entity "contract" it has 5 more field, 2 of these are lookups.
First lookup (agl_contractId) - it is a link by it self
Second lookup (agl_ClientId) - link to Client.
What do I need?
When I choose fill First lookup (agl_contractId), script should find in this contract a Client and copy-past it to current form.
I've done script but it isn't work... (((
function GetAccountFromContract()
{
XrmServiceToolkit.Rest.Retrieve(Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue(),
'agl_osnovnoy_dogovoridSet',
null,null,
function (result) {
var Id = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
if (result.Id != null) {
var LookupData = new Array();
var LookupItem = new Object();
var lookuptextvalue = lookupvalue[0].name;
var lookupid = lookupvalue[0].id;
var lokupType = lookupvalue[0].entityType;
alert(lookupvalue);
alert(lookupData);
Xrm.Page.getAttribute("agl_accountid").setValue(lookupData);
}
},
function (error) {
equal(true, false, error.message);
},
false
);
}
If I understand you well: When you select Contract in agl_osnovnoy_dogovorid field, you want to pull Client property from that Contract and put it in agl_accountid field?
If that is right:
First, get Id of selected Contract (from agl_osnovnoy_dogovorid field)
var selectedContract = new Array();
selectedContract = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
{
var guidSelectedContract = selectedContract[0].id;
//var name = selectedContract[0].name;
//var entType = selectedContract[0].entityType;
}
Second, retrieve Client from agl_osnovnoy_dogovorid. Your oData query will be like:
http://crmserver/org/XRMServices/2011/OrganizationData.svc/ContractSet(guid'" + guidSelectedContract + "')/CustomerId
(In example I'm using CustomerId field. For your case enter Schema Name of Client field).
Now, execute query and put result into agl_accountid field:
$.getJSON(
Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/ContractSet(guid'" + guidSelectedContract + "')/CustomerId",
function(data){
if(data.d.CustomerId != null && data.d.CustomerId.Id != null && data.d.CustomerId.Id != "undefined")
{
//set agl_accountid field
Xrm.Page.getAttribute("agl_accountid").setValue([{id:data.d.CustomerId.Id, name:data.d.CustomerId.Name, typename:data.d.CustomerId.LogicalName}]);
}
});
Your using REST to retrieve data but also using FetchXml example to setup the agl_accoutid lookup.
Also some of the conditions are not clear … anyway … I’ve incorporated the change to your original post.
function GetAccountFromContract()
{
var aodLookupValue = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
if (!aodLookupValue) return;
XrmServiceToolkit.Rest.Retrieve( aodLookupValue[0].id ,
'agl_osnovnoy_dogovoridSet', null,null,
function (result) {
var customer = result.d["your attribute name"];
if (customer) {
var LookupData = new Array();
var LookupItem = new Object();
var lookuptextvalue = customer.Name;
var lookupid = customer.Id;
var lokupType = customer.LogicalName;
alert(lookupvalue);
alert(lookupData);
Xrm.Page.getAttribute("agl_accountid").setValue(lookupData);
}
},
function (error) {
equal(true, false, error.message);
}, false );
}

Extending or modifying the SharePoint Datasheet view

Has anyone discovered a way to extend or modify the functionality of the SharePoint Datasheet view (the view used when you edit a list in Datasheet mode, the one that looks like a basic Excel worksheet)?
I need to do several things to it, if possible, but I have yet to find a decent non-hackish way to change any functionality in it.
EDIT: An example of what I wish to do is to enable cascading filtering on lookup fields - so a choice in one field limits the available choices in another. There is a method to do this in the standard view form, but the datasheet view is completely seperate.
Regards
Moo
I don't think you can modify it in any non-hackish way, but you can create a new datasheet view from scratch. You do this by creating a new ActiveX control, and exposing it as a COM object, and modifying the web.config file to make reference to the new ActiveX control.
There's an example here:
Creating a custom datasheet control.
Actually, you can do this. Here is a code snippet I stripped out of someplace where I am doing just what you asked. I tried to remove specifics.
var gridFieldOverrideExample = (function (){
function fieldView(ctx){
var val=ctx.CurrentItem[curFieldName];
var spanId=curFieldName+"span"+ctx.CurrentItem.ID;
if (ctx.inGridMode){
handleGridField(ctx, spanId);
}
return "<span id='"+spanId+"'>"+val+"</span>";
}
function handleGridField(ctx, spanID){
window.SP.SOD.executeOrDelayUntilScriptLoaded(function(){
window.SP.GanttControl.WaitForGanttCreation(function (ganttChart){
var gridColumn = null;
var editID = "EDIT_"+curFieldName+"_GRID_FIELD";
var columns = ganttChart.get_Columns();
for(var i=0;i<columns.length;i++){
if(columns[i].columnKey == curFieldName){
gridColumn = columns[i];
break;
}
}
if (gridColumn){
gridColumn.fnGetEditControlName = function(record, fieldKey){
return editID;
};
window.SP.JsGrid.PropertyType.Utils.RegisterEditControl(editID, function (ctx) {
editorInstance = new SP.JsGrid.EditControl.EditBoxEditControl(ctx, null);
editorInstance.NewValue = "";
editorInstance.SetValue = function (value) {
_cellContext = editorInstance.GetCellContext();
_cellContext.SetCurrentValue({ localized: value });
};
editorInstance.Unbind = function () {
//This happens when the grid cell loses focus - hide controls here, do cleanup, etc.
}
//Below I grabbed a reference to the original 'BindToCell' function so I can prepend to it by overwriting the event.
var origbtc = editorInstance.BindToCell;
editorInstance.BindToCell = function(cellContext){
if ((cellContext.record) &&
(cellContext.record.properties) &&
(cellContext.record.properties.ID) &&
(cellContext.record.properties.ID.dataValue)){
editorInstance.ItemID = cellContext.record.properties.ID.dataValue;
}
origbtc(cellContext);
};
//Below I grabbed a reference to the original 'OnBeginEdit' function so I can prepend to it by overwriting the event.
var origbte = editorInstance.OnBeginEdit;
editorInstance.TargetID;
editorInstance.OnBeginEdit = function (cellContext){
this.TargetID = cellContext.target.ID;
/*
. . .
Here is where you would include any custom rendering
. . .
*/
origbte(cellContext);
};
return editorInstance;
}, []);
}
});
},"spgantt.js");
}
return{
fieldView : fieldView
}
})();
(function () {
function OverrideFields(){
var overrideContext = {};
overrideContext.Templates = overrideContext.Templates || {};
overrideContext.Templates.Fields = {
'FieldToOverride' : {
'View': gridFieldOverrideExample.fieldView
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
}
ExecuteOrDelayUntilScriptLoaded(OverrideFields, 'clienttemplates.js');
})();
Also, there are a couple of other examples out there. Sorry, I don't have the links anymore:

Resources