Home

Showing posts with label dynamice crm scripts. Show all posts
Showing posts with label dynamice crm scripts. Show all posts

Friday, March 13, 2020

Deactivate forms in Dynamics 365 using power-shell

Install-Module -Name Microsoft.Xrm.Data.Powershell -RequiredVersion 2.8.7 -Scope CurrentUser
#$crmOrg = Get-CrmConnection –InteractiveMode
$password = ConvertTo-SecureString "***" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential("username@domain.com",$password)
$crmOrg = Get-CrmConnection -Credential $credentials -DeploymentRegion NorthAmerica -OnlineType Office365 -OrganizationName "dev-dev" -MaxCrmConnectionTimeOutMinutes 5

Write-Host '------------------------------------------------------------'
Write-Host 'Information: Connection established successfully....'
Write-Information -MessageData "Connection established successfully...." -Tags success
$formNames = @( "Account for interactive experience","Contacts Form"
);

$formsSb = [System.Text.StringBuilder]::new()
for($i = 0; $i -lt $formNames.length; $i++)
{
$formsSb = $formsSb.Append("<condition attribute='name' operator='eq' value='" + $formNames[$i] +"'/>" )
}

$formFetchXml = "<fetch>
<entity name='systemform'>
<attribute name='name' />
<attribute name='isdefault' />
<attribute name='formactivationstate' /> 
<filter type='or'>"+ $formsSb.ToString() +
"</filter>
<order attribute='name' />
</entity>
</fetch>";

$formsToDeactivate = Get-CrmRecordsByFetch -Fetch $formFetchXml -conn $crmOrg
$success = 0
$failure = 0

foreach($formRecord in $formsToDeactivate['CrmRecords'])
{
Set-CrmRecord -EntityLogicalName systemform -Fields @{"formactivationstate"=New-CrmOptionSetValue(0) } -Id $formRecord.formid -conn $crmOrg -PrimaryKeyField formid -ErrorAction SilentlyContinue -ErrorVariable formError
if($formError){
Write-Warning -Message "$($formRecord.name) - Deactivation Failed"
Write-Information -MessageData "$($formRecord.name) ' - Deactivation Failed" -Tags failure
#Write-Error -Message $formError[0].Exception.Message
$failure++
}
else {
Write-Information -MessageData "$($formRecord.name) ' - Deactivated Successfully" -Tags success
Write-Host 'Information: '$formRecord.name ' - Deactivated Successfully'
$success++
}
}

Write-Host '------------------------------------------------------------'
Write-Host 'Information: Total count of forms to be Deactivated - ' $formsToDeactivate.Count
Write-Information -MessageData "Total count of forms to be Deactivated - &($viewsToDeactivate.Count)" -Tags success
Write-Host 'Information: Total count of forms Deactivated Successfully- ' $success
Write-Information -MessageData "Total count of forms Deactivated Successfully - $($success)" -Tags success
Write-Host 'Information: Total count of forms failed to Deactivate - ' $failure
Write-Information -MessageData "Total count of forms failed to Deactivate - $($failure)" -Tags failure
Write-Host '------------------------------------------------------------'

Saturday, September 16, 2017

Show/Hide business process in Dynamics 365


Use getVisible method to retrieve whether the business process control is visible
Xrm.Page.ui.process.getVisible();

Use setVisible method to show or hide the business process flow control.
Xrm.Page.ui.process.setVisible();


// isVisible parameter should be true or false based on your requirement.
function showHideBP(isVisible){   
        Xrm.Page.ui.process.setVisible(isVisible);   
}


Set form notifications in dynamics 365

You can display any number of notifications using “setFormNotification” and they will be displayed until they are removed using clearFormNotification. The height of the notification area is limited so each new message will be added to the top. Users can scroll down to view older messages that have not yet been removed.

Syntax
To clear the notifications on the form.
Xrm.Page.ui.clearFormNotification(uniqueId);
To set  the notifications on the form.
Xrm.Page.ui.setFormNotification(message, level, uniqueId);
To set the notifications on the form for a particular field.
Xrm.Page.getControl(fieldname).setNotification(message, uniqueId);
--------------------------------------------------------------------------------------

To set the notifications on the form.
function setFormNotifications() {
    Xrm.Page.ui.setFormNotification("This is an INFORMATION notification.", "INFO","1");
    Xrm.Page.ui.setFormNotification("This is a WARNING notification. ", "WARNING" , "2");
    Xrm.Page.ui.setFormNotification("This is an ERROR notification. ", "ERROR", "3");
    Xrm.Page.getControl("name").setNotification("Message to display", "101")
}

To clear the notifications from field and form.
function clearFormNotifications() {
    // Cleards notifications from the field "name" with unique identifier 101
    Xrm.Page.getControl("name").clearNotification("101");
    // Clears notifications from the form for unique id 1
    Xrm.Page.ui.clearFormNotification("1");
}

Convert subgrid to Comments