Salesforce Tips - 用python + task scheduler实现报表下载到one-drive自动化

Salesforce有个投票网站,里面有无数个人发起了无数个关于各种功能死角的poll,但是有些问题已经提出了十几年了(其于1999年成立至今不过20年),还在等待poll。这就苦了平常做维护、开发和需求的salesforce人们。

报表下载权限就是其中一项,要么给一个简档(profile)全部active,要么全部disable, 不能通过配置的方式给用户仅开放某些报表的权限,这让徘徊在在数据安全层面和用户实际需求(下载属于他的数据)层面就显得非常为难。

本文介绍一种绕开salesforce关于报表下载的标准配置,通过Python实现自动download, 这样可以帮助有需要的用户拿到他/她想要的报表,而又不active其下载权限。

1. 首先,装包, 在你的Python编译器或者使用jupyter的话,直接在anaconda promt 里面装

    pip install salesforce-reporting

2. 其次,再通过Python实现自动download,将以下代码保存为.py

#Connect to the Salesforce Analytics API and request data from a report

import salesforce_reporting

import pandas as pd

from salesforce_reporting import Connection, ReportParser

# setup your login details

# if your org didnt enable two-authentation, then leave security_token as blank with

apostrophe

sf = Connection(username='xxxx@xxx.com', password='xxxxxx', security_token='xxxx')

#Use the Connection.get_report() method to request report data and then use ReportParser to access all the records

#included in a report (in list format if you use the ReportParser.records() method):

import datetime

def download_report(reportName, reportType):

    report = sf.get_report(reportName)

    parser = salesforce_reporting.ReportParser(report)

    content = parser.records_dict()

    #df = pd.DataFrame(content)

    #print(df)

    columns_order=pd.DataFrame(content[0],index=[0]).columns.tolist()

    df = pd.DataFrame(content, columns=columns_order)


    now = datetime.date.today()

    #title='Salesforce_Report'+ '_'+ reportType +'_'+str(now)+'.xlsx'

    title='your path\Salesforce_Report'+ '_'+ reportType +'_'+str(now)+'.xlsx'

    df.to_excel(title, index=False)

3   最后,设置windows 自带的task scheduler, 实现自动执行上述python代码

      a. windows 搜索task scheduler

      b. create task, 命名等

      c. 添加action, 可以将以下copy替换你的path,并保存在.cmd 或者.bat格式,将此文件添加为action的source

即"python.exe path" ".py file path",

"D:\Program Files in D\Anaconda\python.exe""D:\BA\Requirement\CRM\Salesforce\Report Download\Python Salesfoce Pull Data\Python pull Material Price for Costing from salesforce.py"

      d. 设置你想要的下载频率


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容