How to capture the save ribbon event for custom web part? - sharepoint

I have two webparts on a Project Details Page, webpart #1 is a default form webpart, webpart#2 is a custom webpart with custom form.
Now when I click on "Save" in ribbon it fires the save event for Web Part 1.
My question: Is there a way to capture the save ribbon event, so I can trigger the save event of my custom web part ?
Thank you,

We can specify the OnSaveHandler at runtime as follows,
SPContext.Current.FormContext.OnSaveHandler = btnSave_Click;

You can try to achieve this using javascript. You need to add your custom script block with function PreSaveAction.
Something like this:
<script>
function PreSaveAction(){
//Do your stuff
}
<script>
Please refer to this post.

Related

How can you change current tab programmatically with Acumatica?

When I launch a custom Framework page, i would to be able to activate one of the tabs programmatically depending on certain conditions. Am i stuck using javaScript or is there another way?
There are a few posts already on this question with answers:
This is the best answer: How to conditionally hide PXTabItem inside an Acumatica screen?
Also, searching hide tab you will find what you need.
For information, this can be achieved statically with PXTab control SelectedIndex property:
You can do this using a Javascript function and attaching it to the corresponding client event on your Acumatica form.
Here, I wanted the tab to change based on the index of the active cell in a grid. So I set the aftercellchange and cellclick grid-events(client events) to my gridclick Javascript function. Finally, added this script to my aspx page:
<script type="text/javascript">
function gridClick()
{
var index = px_alls["grid"].activeCell.getIndex();
if(index<=2) px_alls["tab"].items[0].select();
if(index>=3 && index<=5) px_alls["tab"].items[1].select();
if(index>=6) px_alls["tab"].items[2].select();
}
</script>

Dynamic CRM 2011. Hide/show tabs using radio buttons issue

I have this code that hides tabs and shows tabs in CRM 2011. By default all tabs are hidden, but when the client has the product purchased (yes selected), the tab is showen.
The issue I am having is when I click yes and save & close. Then reopen the account, the tab is hidden, but the option is still yes.
The code is:
function showTab(tabNumber, optionField, optionValue) {
if (Xrm.Page.getAttribute(optionField).getValue() == optionValue) {
Xrm.Page.ui.tabs.get(tabNumber).setVisible(true);
}
else {
Xrm.Page.ui.tabs.get(tabNumber).setVisible(false);
}
}
The option I have is:
2,"new_server",'1'
I got the code from this place:
Show a Tab Dynamics CRM 2011
I am still working on this.
You need to register this function on both the form's OnLoad event and the field's OnChange event. It sounds, from your description, that it is registered and working for the OnChange event but the OnLoad event.
You currently have the function registered on the onChange event for the radio button control.
Additionally, you need to register an onLoad event for the form.
Create a new web resource.
Open Form Properties.
Add form to available resources.
Add event handler onLoad, and call your webresource.
In the web resource you can just have a call to your showTab function.
When you open the form for customization, look at the top ribbon of the form. You will see Form Properties icon right next to Preview. Click on Form Properties and then add the JavaScript web resource in the Form Library.
Choose Event: OnLoad from the drop down and then click add under the Event Handler.
Choose the web resource of your choice, add the function name being used in your code (showTab).
This will add the function to your Onload event of the form.

Modifying sharepoint edit dialog

I have successfully created a feature in sharepoint that modifies the existing edit dialog and adds a custom button to it like this.
and I am aware that I can pass back data when the user clicks the custom button like this.
<CommandUIHandlers>
<CommandUIHandler Command="ActivateUser" CommandAction="/_layouts/MyFeature/MakeUserActive.aspx?ListID={ListId}&ItemID={ItemId}&ItemUrl={ItemUrl}&ListUrlDir={ListUrlDir}" />
</CommandUIHandlers>
As detailed here
I can now handle the list item and perform my required actions on it BUT given that this button has been added in the modify context (IE: Inside the sharepoint edit item dialog) what if you want to save changes to the data itself?
To me it seems like using your custom button would always mean losing any changes the user has made to the data. Is there a way around this?
Good question!
You actually already linked to the solution: Right now you are simply redirecting the user by using a URL as your CommandAction: CommandAction="/_layouts/MyFeature/MakeUserActive.aspx?ListID={ListId}&ItemID={ItemId}&ItemUrl={ItemUrl}&ListUrlDir={ListUrlDir}"
This if course redirects the user to another page without saving the current entry. What you want to do is use Javascript as linked in the MSDN article:
CommandAction="javascript:alert('here be dragons');"
You can either work the the SharePoint Javascript object model here and use something like SP.ListOperation.Selection.getSelectedItems(); or you could use complete custom code.
From your aspx page name I can see you want to "make a use active" (btw: wouldn't "ActivateUser.aspx" be nicer?). If this simply means setting a property in another list you could do that with the SharePoint OM, if it is some custom stuff you would need a webservice which you can call from JavaScript and "activate the user" like that. You can of course always access the current form and pass on the values the user entered. Or you could create a custom save button which does some stuff (activate user) before saving.
Lastly: You can also have postbacks in your custom button where you could do anything you'd like.

sharePoint arcitecture custom action in list shown in pop up

this is an image of a sharepoint list action , the sending news letter is a custom action that i added , but when clicking on it , i want it to open a page not redirection, i want it to get a pop up action with a mask behind as the View item do
What you are referring to is the modal framework in sharepoint 2010. You need to change your action javascript code.
Here is an article i've used in the past.
http://www.chakkaradeep.com/post/Using-the-SharePoint-2010-Modal-Dialog.aspx
You need to call ModalDialog Javascript function from your CustomAction rather than redirection.
Here's the URL with example of what you are looking for:
http://www.chakkaradeep.com/post/Using-the-SharePoint-2010-Modal-Dialog.aspx

How do I add new buttons to an existing form?

I want to add new buttons to an existing form.
I want one button that, when clicked, saves the filled in values and reloads the same form.
The second button should save the filled in values and redirect to another form.
How do I add new buttons to the form and provide actions to take for each button?
Is this a webform form, as in created by the Webform module?
If you are talking about a Webform, it sounds like you'll need to create a custom module to provide advanced additional processing. You used to be able to add some additional processing in Webform under the Advanced settings, but to manipulate the buttons the way your describing I assume you'll need to employ the hook_form_alter() function. This post outlines that method for someone with a similar problem: http://drupal.org/node/1050656#comment-4053130
In that module you'll need to point to a special submit handler with something like this
function mymodule_form_alter(&$form, $form_state, $form_id) {
//...
if ( YOURCONDITIONS && in_array($form_id,array('webform-client-form-YOURFORMID'))) {
$form['submit']['#submit'][] = 'mymodule_form_YOURSPECIALHANDLER';
}
}

Resources