Tuesday, November 29, 2016

How to control Windows Shutdown, Sleep, Hibernate ect by Command Line

There are 3 utilities we can use:shutdown.exe , powercfg and PowerProf.dll


Sleep Computer (read more at http://superuser.com/a/463652/249349 )
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
Lock Workstation
Rundll32.exe User32.dll,LockWorkStation
Hibernate Computer
rundll32.exe PowrProf.dll,SetSuspendState
Restart Computer
Shutdown.exe -r -t 00
Shutdown Computer
Shutdown.exe -s -t 00
Sleep from windows task command :
exec show "C:\Windows\System32\rundll32.exe" Powrprof.dll,SetSuspendState Sleep
There are issues with sleep when hibernate is enabled & many confuse the 2 commands:
Another Utility from SysInternals PsShutdown and NirCmd has some very handy utils.
 
The command rundll32.exe powrprof.dll,SetSuspendState 0,1,0 for sleep is correct - however, it will hibernate instead of sleep if you don't turn the hibernation off.
Here's how to do that:
Go to the Start Menu and open an elevated Command Prompt by typing cmd.exe, right clicking and choosing Run as administrator. Type the following command:
powercfg -hibernate off



Additional commands see this post:

Tuesday, November 22, 2016

SharePoint 2013 Workflow Task Assign Multiple Users to Task Participants / Reviewers / Approvers


To assign multiple users to a task  Assigned / Reviewers / Approves property in an SharePoint 2010 or SharePoint 2013 workflow we need to implement a string value based on the following string format :
{UserID Number(n)};#{Display Name(n)};#{UserID Number(n+1)};#{Display Name(n+1)}
1. First create a string var in Workflow: 
2. Assign Value to this string var: Build String using format above, ensure to 
select Return Field As: 'User ID Number' and 'Display Name'
E.g:  [%Current Item:Modified By%];#[%Current Item:Modified By%]
would appear as :
48;#Dole, Jason R
An example of multiple users:
[%Current Item:Modified By%];#[%Current Item:Modified By%];#[%Current Item:Created By%];#[%Current Item:Created By%]

3. Now assign string variable to Participants user field, be sure to select  Return Field As: String when using the string variable created in Step 1 above.

Be sure to include the ;# delimiter in between users, this is  very important
The key is to use ';#' as both a field and user delimiter, 
If you miss a delimiter and/or try to populate using incorrect data a common error is as follows:
[Coercion Failed: Unable to transform the input lookup data into the requested type.]
exception.
Good Luck!

Friday, November 11, 2016

SharePoint Document Attachment Options

We came across quite a few design and implementation aspects within InfoPath forms for handing document attachments, in particular comparing InfoPath Attachments vs document library vs Folders.


In InfoPath forms when a user attaches document attachments to a form, the user experience is clean, however the downstream document management for the user and programmer is difficult due to the fact that documents are embedded in the form as base64 byte arrays.


Below are reference articles that explore the capabilities that exist to extract InfoPath attachments from a form to a SP Library and conversely using Libraries only.


Using InfoPath in WebParts, One-To Many Relationship
 https://jennyssharepointtips.wordpress.com/2014/08/08/display-infopath-forms-or-list-forms-in-an-infopath-form-web-part/
MS Reference Article: InfoPathDecoder:
https://support.microsoft.com/en-us/kb/2517906
InfoPath Attachments What are they?
 http://www.bizsupportonline.net/blog/2010/top-10-questions-infopath-file-attachments.htm

Summary of options:
1. Documents as InfoPath Attachments embedded
- a: Document attached to form, no versioning, no library, no folders
2. Documents as LookUp SiteColumn to Library via Workflow
- User Uploads to DropOff Library then selects via List Form, Workflow takes over, or similar.
3. Documents as InfoPath Attachments, stripped by Code saved to Library (Code)
- a: Form calls custom web service
- b: Form calls custom SP web service
- c: Form calls code behind form
Reference Articles
No Code:
 Attach files via Drop Down:
 https://www.youtube.com/watch?v=Ro36RDFde9c

 Workflow Action:
 https://www.youtube.com/watch?v=_n7YOCb5YVc

 Form Action Option:
 http://m4sh3d.blogspot.com/2013/11/how-to-upload-infopath-2010-attachments.html
Code: (Not Available)
Web Service
http://www.bizsupportonline.net/infopath2007/use-workflow-extract-file-attachment-infopath-upload-sharepoint-document-library.htm
VSTA
https://www.microsoft.com/en-us/download/details.aspx?id=38807
InfoPathDecoder:
https://support.microsoft.com/en-us/kb/2517906

Form Call a Web Service:
https://www.youtube.com/watch?v=aGYqQG8D4so


3rd Party Solutions:
1. Workflow Actions:
Copy List attachments to Document Library
https://www.virtosoftware.com/manual/workflow-activities-extensions-for-microsoft-sharepoint-designer/copy-list-attachments-to-document-library



SharePoint 2013 Customize Task Form



<script language="javascript">
                            function isEqual(str1, str2, doExactMatch)
                            {
                            var result = false;
                            try
                            {
                            if (doExactMatch == true)
                            {
                            result = (str1.trim().toLowerCase() == str2.trim().toLowerCase());
                            }
                            else
                            {
                            result = (str1.trim().toLowerCase().indexOf(str2.trim().toLowerCase()) >= 0);
                            }
                            }catch(err){result = false;}
                            return result;
                            }
                            function getFormRowByCaption(tbl, cap, formCaptionIndex, doHide, doExactMatch)
                            {
                            var result = null;
                            try
                            {
                            console.log('getFormRowByCaption() -> START');
                            if (tbl.id != null)
                            console.log('getFormRowByCaption() -> tbl ID-> ' + tbl.id);
                            else
                            console.log('getFormRowByCaption() -> tbl ID-> ' + tbl[0].outerHTML.trim().substring(0,20));
                            //console.log('getFormRowByCaption() -> tbl .exists()-> ' + tbl.exists());
                            console.log('getFormRowByCaption() -> tbl length-> ' + tbl.length);;

                            //$('tr').each(function()
                            tbl.find('tbody tr').each(function()
                            {
                            var atd = $(this).find('td').eq(formCaptionIndex);
                            var isMatch = false;
                            try
                            {
                            console.log('getFormRowByCaption() -> atd.Text()-> ' + atd.text().trim());
                            //(atd.text().trim().toLowerCase().indexOf(cap) >= 0);
                            isMatch = isEqual(atd.text(), cap, doExactMatch);
                            }
                            catch(err){isMatch = false;}
                            try{if (isMatch == false) isMatch = isEqual(atd[0].innerText, cap, doExactMatch);}
                            catch(err){isMatch = false;}
                            try{if (isMatch == false) isMatch = isEqual(atd[0].innerHTML, cap, doExactMatch);}
                            catch(err){isMatch = false;}

                            if ( isMatch==true )
                            {
                            result = atd.closest("tr");
                            try{
                            console.log('getFormRowByCaption() -> FOUND ROW!');
                            console.log('getFormRowByCaption() -> RESULT-> '
                            + result[0].outerHTML.trim().substring(0,50));
                            }
                            catch(err){}
                            if (doHide == true)
                            result.hide();
                            return false;
                            }
                            });
                            console.log('getFormRowByCaption() -> DONE');
                            }
                            catch(err){}
                            return result;
                            }
                            $(document).ready(function() {
                            try
                            {
                            /*****************************************
                            // Task 241
                            task Form Shall show in order:
                            1. Display:  Task Name
                            2. Display:  Task Due Date
                            3. Data entry: Change Assigned To.  (not necessary, but the users like it)
                            4. Add comments field.
                            5. Data entry: Enter a Reject Reason (if applicable to task).
                            5. Allow Comments
                            ******************************************/
                            /*****************************************
                            // Task 86 Change Field Title from Choose Purchase Order Document to  Choose SA Purchase Order
                            ******************************************/
                            if (document.URL.indexOf('LeasingLeasingDealPipeline/EditTM.aspx') || document.URL.indexOf('LeasingLeasingDealPipeline/EditDeal.aspx'))
                            {
                            var ftr = getFormRowByCaption($('table.deal-UI-table:first')  , 'Choose Purchase Order Document', 0, false, false);
                            if (ftr) ftr.find("td:first>.ms-standardheader").text('Choose SA Purchase Order');

                            }
                            if (document.URL.indexOf('Leasing/WorkflowTasks/EditForm.aspx') && $('[id*=SaveItem]') != null && document.URL.indexOf('/WorkflowTasks/') > 0 )
                            {
                            /*****************************************
                            // Task 52 Save Button Hide
                            // Workflow Task Save Button Hide All Forms in lieu of Form Content Type mods abc
                            ******************************************/
                            // save button
                            if ($('[id*=ContentTypeChoice] option:selected') != null)
                            {
                            var contenttype = $('[id*=ContentTypeChoice] option:selected').text().toLowerCase();
                            if ((contenttype == "request ls rlm approval" || contenttype == "request rsm approval" || contenttype == "request new collo app") || (/^sa/).test('sa'))
                            $('[id*=SaveItem]').css('display', 'none');
                            }
                            //   return;
                            // TASK
                            // problem task outcome
                            //http://stageportal.verticalbridge.com/Leasing/WorkflowTasks/EditForm.aspx?ID=3121&Source=http%3A%2F%2Fstageportal%2Everticalbridge%2Ecom%2FLeasing%2FPages%2FDealDashboard%2Easpx%3FDealNo%3DD-001423

                            var tbl = $('table.ms-formtable:first');
                            // content type
                            getFormRowByCaption(tbl , 'content', 0, true, false);
                            //start date
                            getFormRowByCaption(tbl , 'start date', 0, true, true);
                            //pct conplete
                            getFormRowByCaption(tbl , '% complete', 0, true, true);
                            //priority
                            getFormRowByCaption(tbl , 'priority', 0, true, true);
                            //status
                            getFormRowByCaption(tbl , 'status', 0, true, true);
                            //deal num
                            getFormRowByCaption(tbl , 'deal number', 0, true, true);
                            // Misc cls that may appear
                            //Related Items
                            getFormRowByCaption(tbl , 'Related Items', 0, true, false);
                            //RequestNewColloApp
                            //   debugger;
                            getFormRowByCaption(tbl , 'RequestNewColloApp', 0, true, true);
                            //RequestNewColloApp
                            getFormRowByCaption(tbl , 'RequestRSMApproval', 0, true, true);
                            //RequestNewColloApp
                            getFormRowByCaption(tbl , 'Workflow Comments', 0, true, true);

                            // show more
                            //if ($('a.ms-commandLink') != null)
                            // $('a.ms-commandLink').hide();
                            rlfiShowMore();

                            /**************
                            Task 306: Task Comment.
                            ***************/
                            // Hide comments span:
                            var ftr2 = getFormRowByCaption(tbl, 'Comments', 0, false, false);
                            if (ftr2 != null)
                            ftr2.find("td:last > span:last").hide();
                            }
                            }catch(err){}
                            });
                          </script>

SharePoint 2013 Task Form Show/Hide Field Caveats:


Task Out Comes Disappear:
Make sure that, "%complete" and "task status" fields are not hidden in content type. They are necessary for task outcome works correctly.


Content Type Drop Down Displays:Open the Workflow Task list through SharePoint Designer 2013.
Under setting panel there is a check box for “Allow management of content types”. Un tick that check box and save.




Sources:
http://jsuhail.blogspot.com/2014/06/remove-content-type-drop-down-in.html
https://social.msdn.microsoft.com/Forums/office/en-US/16635209-28f8-481b-a909-a5bb79576333/task-outcome-buttons-disapeared?forum=sharepointcustomization