Save and Continue for selected Records

Hi to all,
i need to implement a fast way to edit only specific fields in selected records.

I thought about save and continue feature.
The behavior should looks like this:

  1. Select some records in list view
  2. click Edit pencil icon in one of selected records or add specific action button
  3. using save and continue to edit the specific fields

Of course, better could be to have a specific view in order to let user to edit only these fields

Mass update cannot be used cause the values to edit will vary depending on records

Does anyone can help me to achieve this?
As far as i know save and continue works only when a filter is applied

Many Thanks

I think that you can:

  1. add button to BULK ACTION menu;
  2. change the variable $_SESSION[$module.'QUERY_ARRAY'] (Look at the file include/EditView/SugarVCR.php. The function menu create the button prev and next);
  3. add create different form (look at posts 1 and 2).
    Custom View depending field value
    Custom View depending field value

It sound really interesting…and I will try.
What about realizing the same behavior in subpanel?
What is missing is a checkbox for every record and select all action.

Do you think it can be achievable?

Many thanks

@rainolf

You can for start:

  1. add the button SubPanelTopFilterButton into subpanel
  2. write and add a custom button into subpanel which will open the first record for edit after filter.
  3. use points 2 and 3 from my post before.

Cool!
i am starting step by step by using at first getMetaDataFile example you posted and i am able to show only
fields i need to display.

Due to the needs to add custom validation in this new metadata file i suppose i need also to use a custom view edit.

Am i right? How can i inject a different edit-view in this scenario?

Many thanks

@rainolf

If I understand you correctly.
I see two ways:

  1. You can have multiple fixed options of forms for EditView.
  2. You can dynamically change the form using the function getMetaDataFile (create temporary file).

Let me show you what i’ve done so far:

if (!defined('sugarEntry') || !sugarEntry) {die('Not A Valid Entry Point');}
//#!@ # BEGIN #!@################################################################
require_once('include/MVC/View/views/view.edit.php'); 
class CDZ_Items_TelcoViewEdit extends ViewEdit
{
    public function getMetaDataFile() {
        switch($this->bean->service_type) {
            case 'Mobile':
                $metaType = $this->type;
                $this->type = $metaType . '_mobile_';
            break;
            case 'Internet':
                $metaType = $this->type;
                $this->type = $metaType . '_internet_';
            break;
            case 'Landline':
                $metaType = $this->type;
                $this->type = $metaType . '_landline_';
            break;
            default:
                $this->type = $oldType;
        }    
        $metadataFile = parent::getMetaDataFile();
        return $metadataFile;
    }

    public function display(){
        switch($this->bean->service_type) {
            case 'Mobile':
                $this->ev->formName='EditView_Mobile';
            break;
            case 'Internet':
                $this->ev->formName='EditView_Internet';
            break;
            case 'Landline':
                $this->ev->formName='EditView_Landline';
            break;
        }
        parent::display();
    }
    //#!@ # END #!@#############

Currently i’ve set different metadata for different service type and changed form name too.
Every metadata let show to the user a set of fields which muust be validated differently.

EX: for Mobile only Mobile Number and ICCID is mandatory while for Landline and Internet we also to validate addresses.

What i need to achieve is custom validation based on Service Type but i am confused if different view is needed or not.

@rainolf

What do you mean?

Service Type is the field used to change metadata file aka displayed information on the view.

Based on Service Type i will have:

  • edit_mobile_viewdefs.php
  • edit_internet_viewdefs.php
  • edit_landline_viewdefs.php

Now i need to cutsom validate, and from what i’ve seen i could do everything in function display() by checking which FormName has been used.

Am i right?

@rainolf

Yes, I see that you did all correct. For information:

  1. The code into function getMetaDataFile set the metafile.
  2. The code into function display set the prefix name for cache file.

The only problem in the display function above is that this error occured:
Uncaught TypeError: this.get(…) is null

Not able to understand why

@rainolf
Change function getMetaDataFile
Variable $oldType is not initialised.

  1. Insert
$oldType=$this->type;

at the beginning

  1. Insert
$this->type = $oldType;

after call parent::getMetaDataFile(); and before return

look at the example carefully.

Ok…so $oldType is not arbitrary…understood.

Many thanks

The code getMetaDataFiel() is correct now but the error is still coming.

If i remove the function display() the error disappear so semms related to display.

Any hint?

@rainolf
Maybe it is because you don’t create default for switch.

Even adding as per your right suggestion default in switch it didn’t work.
However the error came from gettab function in sugar_grp1_yui
Thats because the new metadata files has no tabs but the definition still use:
‘useTabs’ => true,

Set to false resolved the issue.

Thank you for pointing me.

Save is doneand works without problem, next error comes using “Save and Continue” with same js files above:

Uncaught TypeError: v is undefined

It becomes a nightmare!

It is for sure related to display function and form name change based on field value.
If i remove this code portion, then caching does not works as per your previous post.
If i keep it seems that Save and Continue wants additional information in order to process correctly the form.

@rainolf

One moment. I im checking.

@rainolf

There is a problem this button Save and Continue. It has a fixed form name. I see only one decision. Create custom button. You should write short code which will be replace function SUGAR.saveAndContinue of file include/EditView/SugarVCR.php . the function will have 2 lines only:

SUGAR.saveAndContinueCustom = function (elem){
    elem.form.action.value='Save';
    sendAndRedirect('<name_of_form>', '{$app_strings.LBL_SAVING} {$module}...', '{$list_link}');
}

<name_of_form> - correct form name. It can be insert when script loading.